2
votes

I am trying to include the 7-digit git hash in the artifact name built by my Azure Devops build pipeline. In my build agent job I have an inline powershell script with the following lines:

$commitId = "$(Build.SourceVersion)"
$shortCommitId = ("$commitId").SubString(0,7)

In the options for the Powershell script under "Output variables" I add a reference name: ps.

Then in the Publish Artifact step right after my Powershell step I set the artifact name as:

$(ApplicationName)_Rel_$(ps.shortCommitId)_$(build.buildnumber)

The actual result after the pipeline has finished running is:

MyApplication_Rel_$(ps.shortCommitId)_20190918.1

How do I pass the variable shortCommitId between steps so that it will be part of the artifact name? MyApplication_Rel_04f53f_20190918.18.

1

1 Answers

3
votes

Just add another line that create a variable to the next steps:

Write-Host "##vso[task.setvariable variable=shortCommitId;]$shortCommitId"

In the Publish Artifacts task use the varaible $(shortCommitId):

$(ApplicationName)_Rel_$(shortCommitId)_$(build.buildnumber)

Another option, if you want to use it as an output varaible, is to add isOutput=true:

Write-Host "##vso[task.setvariable variable=shortCommitId;isOutput=true]$shortCommitId"

And now you can use the $(ps.shortCommitId).