Use Git Short Hash in Azure DevOps Release Pipeline

 

I wanted to include the Git Short Hash in the release name of my Azure DevOps Release Pipeline.

I am sure there may be other ways to do this but wanted to show how I did it using PowerShell.

As always I have this as a task group so I can reuse across projects. However, it only has 1 step:

 

 

 

 

The PowerShell within this step looks like this:

$commitId= “$env:BUILD_BUILDNUMBER”

$definitionName= “1.0.0-“

$deploymentId = “$env:RELEASE_DEPLOYMENTID”

$releaseName=$definitionName+$commitId + -$deploymentId

Write-Host (“##vso[release.updatereleasename]$releaseName”)

 

 

 

 

 

 

 

One issue I have found with this is that this obviously only updates once the release has been successfully deployed:

 

 

 

This is because it runs as part of the Release Pipeline. Here is a view of the logs to see it in action:

 

 

 

I figured out the command required to update the release name from these Microsoft Docs at the very bottom under “Release Logging Commands”

Hope you find this post useful and it will help you to build your Infrastructure in Azure using Azure Devops with custom Release Names.

Any questions just get in touch via Twitter

Please follow and like us:

Leave a Reply

Your email address will not be published. Required fields are marked *