Set a Git Tag on Azure
Published by marco on
As with installing a dotnet tool on Azure, there isn’t a standard task for setting a Git tag from a pipeline YAML configuration. The Pipeline UI has an option to easily do this, but that hasn’t translated to a task yet, nor does it look like it’s likely to, according to online discussions.
Setting a Git tag is relatively straightforward, but is complicated by permissions (as with installing a dotnet tool. To tag a build, you have to just execute the git
commands in a script.
− task: CmdLine@2
displayName: Push Git Tag
inputs:
script: |
git tag $(Build.BuildNumber)
git push origin $(Build.BuildNumber)
If, for whatever reason, you want the tag to be created by the triggering user, then include the following lines as well:
− task: CmdLine@2
displayName: Push Git Tag
inputs:
script: |
git config user.email $env:BUILD_REQUESTEDFOREMAIL
git config user.name $env:BUILD_REQUESTEDFOR
git tag $(Build.BuildNumber)
git push origin $(Build.BuildNumber)
You should include this step after the version number has been updated.
With the task in place, you have to ensure that you’ve granted permissions to the proper user.
- Go to the “project settings”
- Select “Repos/Repositories”
- Select the “Permissions” tab
- Allow the specific permission “Contribute” for the “Project Collection Build Service” user.[1]
Granting Repository Permissions