Azure-devops-docs: Is there a way to add git commit hash to the build name?

Created on 26 May 2020  Â·  6Comments  Â·  Source: MicrosoftDocs/azure-devops-docs

[Enter feedback here]


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Pri3 cba devops-cicd-procestech devopprod product-question ready-to-doc

All 6 comments

the example goes like:
$(TeamProject)_$(Build.DefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r)

Could we have something like
$(Date:yyyyMMdd)-$(Time:hhMMSS)-$(SourceCommitHash)
?

any updates on that?

@jacum Apologies for the delay.

Please try using Build.SourceVersion as referenced from this post.

A similar example with $env:BUILD_SOURCEVERSION is posted here.

Thank you for paying attention to my question.

I tried it and it works, but in case of Git I get long hash commits, not very usable as part of BuildNumber.

This proposal
https://developercommunity.visualstudio.com/idea/1026034/add-support-substring-functions-in-azure-pipelines.html
contains solution, but it's not implemented yet... is it?

You're welcome.

Thank you for providing the link, we can see if the product team will implement an easier way to handle this.

For now, directly formatting variable strings is not yet supported and the work-around is to use PowerShell, please refer to this post.

I'd recommend something like:

- bash: |
    HASH=$(git rev-parse --short $BUILD_SOURCEVERSION)
    echo "##vso[build.updatebuildnumber]mybuildname-$HASH"
Was this page helpful?
0 / 5 - 0 ratings

Related issues

dannyvv picture dannyvv  Â·  3Comments

atrauzzi picture atrauzzi  Â·  3Comments

csutorasr picture csutorasr  Â·  3Comments

cijujoseph picture cijujoseph  Â·  3Comments

sevaa picture sevaa  Â·  3Comments