【问题标题】:Passing output variables between Azure Devops build pipeline steps, for example 7 digit git hash在 Azure Devops 构建管道步骤之间传递输出变量,例如 7 位 git hash
【发布时间】:2020-01-19 04:01:53
【问题描述】:

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

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

在“输出变量”下的 Powershell 脚本选项中,我添加了一个引用名称:ps

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

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

管道运行完毕后的实际结果是:

MyApplication_Rel_$(ps.shortCommitId)_20190918.1

如何在步骤之间传递变量 shortCommitId 以使其成为工件名称的一部分? MyApplication_Rel_04f53f_20190918.18.

【问题讨论】:

    标签: azure-devops azure-pipelines build-pipeline


    【解决方案1】:

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

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

    在 Publish Artifacts 任务中使用变量 $(shortCommitId):

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

    如果你想将其用作输出变量,另一种选择是添加isOutput=true

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

    现在您可以使用$(ps.shortCommitId)

    【讨论】:

      猜你喜欢
      • 2021-04-30
      • 2021-02-20
      • 2022-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多