Git tag name in Azure Devops Pipeline YAML
Ok, this was a bit trickier than I expected. Here's the step required to set the variable:
steps:
- script: VERSION_TAG=`git describe --tags` && echo "##vso[task.setvariable variable=VERSION_TAG]$VERSION_TAG"
displayName: Set the tag name as an environment variable
This script sets the variable VERSION_TAG to the name of the latest git tag. It does so in three steps:
1: git describe --tags
Prints the name of the current/latest tag
2: VERSION_TAG=`...`
Sets the output of step 1 to a local variable
3: echo "##vso[task.setvariable variable=VERSION_TAG]$VERSION_TAG"
Prints out a command that sets the variable in Azure Devops. The local variable set in step 2 is used as the value.
For windows vm, you can use the script below to get tag:
steps:
- powershell: |
$CI_BUILD_TAG = git describe --tags
Write-Host "##vso[task.setvariable variable=CI_BUILD_TAG]$CI_BUILD_TAG"
displayName: 'Set the tag name as an environment variable'