trying to build an Android project, gradle checkout the specific branch that was triggered by Azure DevOps and build the package. After task finish Azure Pipelines checkout to HEAD. As a result, in the next task when i get branch name/tag, doesn't print the branch name(feature/Android_fix_something). I would like to rename apk file with name of tag(Android_fix_something.apk).
Asked
Active
Viewed 2,726 times
2 Answers
2
You're looking for Build.SourceBranchName
:
Build.SourceBranchName
The name of the branch in the triggering repo the build was queued for.
Git repo branch or pull request: The last path segment in the ref. For example, in refs/heads/master this value is master. In refs/heads/feature/tools this value is tools.

jessehouwing
- 106,458
- 22
- 256
- 341
0
Based on your description, the Android_fix_something is the tag name of the commit.
If your pipeline is not directly triggered by the commit tag, I am afraid that there is no such predefined variable to get this value.
To get the tag name , you can try the following PowerShell script to get it and set it as the pipeline variable.
- powershell: |
$tag = git describe --exact-match $(Build.SourceVersion)
echo "##vso[task.setvariable variable=tagname;]$tag"
displayName: 'PowerShell Script'
Then you can use the variable $(tagname)
in the next tasks.

Kevin Lu-MSFT
- 20,786
- 3
- 19
- 28