Azure devops 在Azure Devops构建管道步骤之间传递输出变量,例如7位git哈希

Azure devops 在Azure Devops构建管道步骤之间传递输出变量,例如7位git哈希,azure-devops,azure-pipelines,build-pipeline,Azure Devops,Azure Pipelines,Build Pipeline,我试图在我的Azure Devops构建管道构建的工件名称中包含7位git哈希。在生成代理作业中,我有一个内嵌powershell脚本,其中包含以下行: $commitId=“$(Build.SourceVersion)” $shortCommitId=(“$commitId”)。子字符串(0,7) 在“输出变量”下的Powershell脚本选项中,我添加了一个参考名称:ps 然后,在Powershell步骤之后的发布工件步骤中,我将工件名称设置为: $(ApplicationName)_Re

我试图在我的Azure Devops构建管道构建的工件名称中包含7位git哈希。在生成代理作业中,我有一个内嵌powershell脚本,其中包含以下行:

$commitId=“$(Build.SourceVersion)”
$shortCommitId=(“$commitId”)。子字符串(0,7)
在“输出变量”下的Powershell脚本选项中,我添加了一个参考名称:
ps

然后,在Powershell步骤之后的发布工件步骤中,我将工件名称设置为:

$(ApplicationName)_Rel_$(ps.shortCommitId)_$(build.buildnumber)
管道运行结束后的实际结果为:

MyApplication_Rel_$(ps.shortCommitId)_20190918.1

如何在步骤之间传递变量shortCommitId,使其成为工件名称的一部分
MyApplication\u Rel\u 04f53f\u 20190918.18

只需在下一步中添加另一行即可创建变量:

Write-Host "##vso[task.setvariable variable=shortCommitId;]$shortCommitId"
在发布工件任务中,使用变量
$(shortCommitId)

如果要将其用作输出变量,另一个选项是添加
isooutput=true

Write-Host "##vso[task.setvariable variable=shortCommitId;isOutput=true]$shortCommitId"
现在您可以使用
$(ps.shortCommitId)

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