Skip to content

Instantly share code, notes, and snippets.

@mwwhited
Created August 21, 2021 03:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mwwhited/163a12c7fa6398981a3f03f7142645e3 to your computer and use it in GitHub Desktop.
Save mwwhited/163a12c7fa6398981a3f03f7142645e3 to your computer and use it in GitHub Desktop.
Azure Deops Tag Branch on Build

Azure DevOps Pipeline Branch Tagging

Summary

It is possible to git repositories in Azure Devops as part of your automated build process.

Build Scripts

Manually checkout your git repository need the beginning of your job. Ensure to persist credentials so you can authenticate against git later.

  - checkout: self
    clean: true
    persistCredentials: true
    

Near the end if your build process you can add a script to add a tag to git.

  - script: |
            git config --global user.name "AzureDevOps Agent"
            git tag "$(buildVersionTag)" --force
            git push origin "$(buildVersionTag)" --force
            echo "Tagging $(Build.Repository.Name) with $(buildVersionTag)"
    displayName: 'Tag Branch'
    condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))

Make sure to configure the security in your project to allow the build to add tags and contibute

  1. Project Settings
  2. Repos/Repositories
  3. Select chosen repository (or global build account)
  4. Navigate to Security to build user
  5. Set "Contribute" and "Create tag" to "Allow"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment