Reading Time: 4 minutes
Follow by Email

In this article, I am going to walk through the process of using Azure Container Registry (ACR) tasks to automate building Docker container images when you commit source code to a git repository. By doing this you can save yourself a lot of time. 


If you do not have a PAT then follow below to create one.

Go to

In the description box type something like” ACR Auto Build”

Under the scopes section you will see repo. Here tick repo:status and public_repo

Scroll down and then click Generate token and enter your password if asked.

Save the new token into a safe place like LastPass. You will need this later.

Lets create the build task

That’s the prerequisites out of the way, on to the fun stuff, building the build task.

Open the Azure Cloud Shell via the Azure Portal or via and select Bash.

In here you can set some environment variables. This is an optional step, but it does make following this guide easier. If you skip this step then you will have to enter your details manually with each command.

So to set the variables type the following.

Now we can actually create the task. To do this in the Cloud Shell Bash window make sure you are connected to the subscription your ACR is in and then type the following.

So what did you just do?  The above command creates the ACR build task. It sets the context to the ACR, it then calls the task whatever you input for –name. The –image is the section that names the new container image. The {{.Run.ID}} forms the tag value. This ensures the image is tagged uniquely. –Context just links to your git repo. Then you set what branch to use with the –branch switch. –file is the location and name of your docker file. The — git-access-token is the token you created earlier from GitHub.

If you are creating Windows containers than you need the –platform switch. If you are creating Linux containers than you do not need to supply it.

Time to test!

The task has been built, but has not ran yet. You could push some code to your repo and branch, or you could run the task manually.

Run the task manually

In the cloud shell run the following. If you have changed the task name before, just make sure you change it here too.

Success, the container created!

Run a build via a commit

If you cloned my repo then just edit the html file using vscode and push the changes back to your repo.

After you have committed your changes, the webhook that ACR Tasks created fires and starts the build process. If you would like to view the logs you can use the following command.

Check your builds

You can view the status of your builds by using the following command.

As you can see in the image above, I have two failed builds as the platform mismatched and two successful builds, one manually started and one via commit.

You can also view this information and log files from within the Azure portal. If you navigate to Container Registries, and then your container registry. On the left under Services is Tasks click that and you will have a list of all the tasks and a link to each log file.

There you have it every time you push code to your GitHub repo a new container image is built!

I hope you found this article helpful. If you have any questions please reach out.

Follow by Email

Pixel Robots.

I’m Richard Hooper aka Pixel Robots. I started this blog in 2016 for a couple reasons. The first reason was basically just a place for me to store my step by step guides, troubleshooting guides and just plain ideas about being a sysadmin. The second reason was to share what I have learned and found out with other people like me. Hopefully, you can find something useful on the site.


Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *