Skip to main content
Jorge Bernhardt Jorge Bernhardt
  1. Posts/

Azure Container Registry (ACR) - Part 3

·606 words·3 mins· 100 views · 5 likes ·
ACR Azure PowerShell Connect-AzAccount Containers

Hello everyone, as I mentioned in my previous post, today I want to show you how you can use a webhook to trigger events when certain actions are performed in your Azure container registry (ACR). With this latest post in the series, we have reviewed all the cmdlets currently available to manage an ACR using Azure PowerShell.

ACR PowerShell

Prerequisites>

Prerequisites #

  • This tutorial assumes that you already have a Microsoft Azure account configured.
  • You already have an Azure Container Registry (ACR) and are properly configured. If you want to know how to create it, see this link.
Azure PowerShell Workaround>

Azure PowerShell Workaround #

If you want to know how to install the PowerShell Azure module on your machine, check out this link. The simplest way to get started is to sign in interactively at the command line.

Connect-AzAccount

This cmdlet will bring up a dialog box prompting you for your email address and password associated with your Azure account. If you have more than one subscription associated with your mail account, you can choose the default subscription. To perform this task, we will use the following commands:

Get-AzSubscription
Select-AzSubscription -Subscription "My Subscription"

Once you set your default subscription, you’re ready to start.

Set the variables>

Set the variables #

Here, we define the characteristics of our environment and the resource’s properties.

$resourceGroupName = 'RG-DEMO-WE'
$azcRegName = 'acrdemowe'
$acRegWebHook = 'AcRegWHWe'
Creates a container registry webhook>

Creates a container registry webhook #

To create a webhook using the Azure PowerShell, use the New-AzContainerRegistryWebhook cmdlet with the following syntax.

New-AzContainerRegistryWebhook  `
    -Name $acRegWebHook `
    -ResourceGroupName $resourceGroupName `
    -RegistryName $azcRegName `
    -Uri https://www.jorgebernhardt.com `
    -Action push
##
# -Uri: The URI where the webhook should send POST notifications.
#
# -Action: You must set one or more actions that will cause the webhook to post notifications.
#
# -Scope: You can specify for a specific repository or tag. If not specified, the scope is for all events in the registry.
##

New-AzContainerRegistryWebhook

Test the Webhook>

Test the Webhook #

To test it, use the Test-AzContainerRegistryWebhook cmdlet with the following syntax. This command sends a generic POST request and records the response.

Test-AzContainerRegistryWebhook  `
    -Name $acRegWebHook `
    -ResourceGroupName $resourceGroupName `
    -RegistryName $azcRegName
Test-AzContainerRegistryWebhook
>

Test-AzContainerRegistryWebhook
#

As you can see in the following image, the details of the events are recorded in the webhook section of your ACR.

ACR webhook
>

ACR webhook
#

Gets all the events of a webhook>

Gets all the events of a webhook #

Use the Get-AzContainerRegistryWebhookEvent cmdlet to see the test results performed.

Get-AzContainerRegistryWebhookEvent `
    -WebhookName $acRegWebHook `
    -ResourceGroupName $resourceGroupName `
    -RegistryName $azcRegName
Get-AzContainerRegistryWebhookEvent
>

Get-AzContainerRegistryWebhookEvent
#

Updates a container registry webhook>

Updates a container registry webhook #

If you want to make changes to the webhook configuration, you should use the Update-AzContainerRegistryWebhook cmdlet with the following syntax.

Update-AzContainerRegistryWebhook `
    -Name $acRegWebHook `
    -ResourceGroupName $resourceGroupName `
    -RegistryName $azcRegName `
    -Action delete,push

In the previous example, the delete action is added to the webhook configuration.

Update-AzContainerRegistryWebhook
>

Update-AzContainerRegistryWebhook
#

Check the current configuration for a webhook>

Check the current configuration for a webhook #

To verify the settings established in the previous step, use the Get-AzContainerRegistryWebhook cmdlet with the following syntax.

Get-AzContainerRegistryWebhook `
    -Name $acRegWebHook `
    -ResourceGroupName $resourceGroupName `
    -RegistryName $azcRegName `
    -IncludeConfiguration
Get-AzContainerRegistryWebhook
>

Get-AzContainerRegistryWebhook
#

Removes a container registry webhook>

Removes a container registry webhook #

Finally, to remove a container registry webhook, you should use the Remove-AzContainerRegistryReplication cmdlet as shown below.

Remove-AzContainerRegistryWebhook `
    -Name $acRegWebHook `
    -ResourceGroupName $resourceGroupName `
    -RegistryName $azcRegName

Thank you for reading my post. I hope you found this series of articles about Azure container registration helpful. If you want to know more about Azure Container Registry, check out this link: https://docs.microsoft.com/en-us/azure/container-registry/