How can we improve Azure DevOps?

Add the git commit SHA to build number variables

This suggestion is migrated to Developer Community. Please use below link to view the current status.
https://developercommunity.visualstudio.com/content/idea/365571/add-the-git-commit-sha-to-build-number-variables.html
VSTS -> Build Definition -> General -> Build Number Format

It would be lovely to have the $(Build.SourceVersion) available to add to build names.

Example:
Build number format: $(BuildDefinitionName).$(date:yyyyMMdd)$(rev:.r).$(Build.SourceVersion)

Output:
BuildName.20160719.1.78e54363

Also, it would be nice to have a variable for the short SHA.

Example:
Build number format: $(BuildDefinitionName).$(Build.SourceVersionShort)

Output:
BuildName.78e54363

45 votes
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    Signed in as (Sign out)

    We’ll send you updates on this idea

    David Chen shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    8 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      Signed in as (Sign out)
      Submitting...
      • Andreas commented  ·   ·  Flag as inappropriate

        Would be nice to have this out of the box.
        We use a slightly modified PowerShell script which keeps the original configured build number and appends the Commit ID:
        Write-Host ("##vso[build.updatebuildnumber]$env:BUILD_BUILDNUMBER" + "_" + $env:BUILD_SOURCEVERSION.Substring(0,8))

      • kyle commented  ·   ·  Flag as inappropriate

        The workaround for this is to specify your Build Number Format as $(BuildDefinitionName) as a placeholder. Then at some point in your build, have a powershell task with an inline script like this: Write-Host ("##vso[build.updatebuildnumber]$env:BUILD_DEFINITIONNAME " + $env:BUILD_SOURCEVERSION.Substring(0,8))
        When you queue a build you will see it start out named "My Build" until your script echoes the updated number.

      • kforce commented  ·   ·  Flag as inappropriate

        +1 for $(Build.SourceVersionShort), the 40 char commit is too long

      • Aaron Coleman commented  ·   ·  Flag as inappropriate

        I can't believe this isn't already in there -- we'd really like to quickly see in the build & release pipeline what SHA is associated so we can quickly pull that up and debug from that info. Let's rub a little high-priority dev ops on this one!

      Feedback and Knowledge Base