'Azure Container Registry | How do I get the same/current versioning Git Tag Repo for my docker tag image and my ACR, inside of the azure pipeline?

I'm currently try to find a better way to do my git tags since I want to do the NPM versioning and use the same tag into my container registry in Azure. How can I use the same tag from my repo into the git tag? What I'm trying to do in here is that the same git repo tag needs to be the same as the one that my docker image will have. In this case, my repo tag and my container registry will reflect the same tag.

Example:

Repo-Tag:
V1.0.0

Docker image:
V1.0.0

Azure Container Registry:
V1.0.0

Does anyone knows the best thing to do in here?



Solution 1:[1]

In the build pipeline, you can use the predefined build variables Build.SourceBranch or Build.SourceBranchName to get the name of the source branch / tag of the build.

  • If the build is triggered from a branch, the value of the predefined variable is the branch name.
  • If the build is triggered from a tag, the value of the predefined variable is the tag name.

enter image description here

On the docker build task, you can try like as below to set the image tag.

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1