是否可以在我的 Azure DevOps 构建管道“发布工件"中有条件地设置工件名称?任务? [英] Is it possible to conditionally set the artifact name in my Azure DevOps build pipeline "publish artifact" task?

查看:17
本文介绍了是否可以在我的 Azure DevOps 构建管道“发布工件"中有条件地设置工件名称?任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以在我的 Azure DevOps 构建管道发布工件"任务中有条件地设置我的构建工件的名称?我想根据构建管道的输入生成不同的工件.假设,基于输入管道变量,我想生成三个工件之一(红色"、蓝色"、绿色").是否可以根据输入变量指定在我的发布工件"任务中生成的工件,或者仅生成三个构建管道是否更容易/更好?

I was wondering if it is possible to conditionally set the name of my build artifact in my Azure DevOps build pipeline "publish artifact" task? I want to produce different artifacts based on the input to my build pipeline. Say, based on the input pipeline variables, I want to produce one of three artifacts ("red", "blue", "green"). Is it possible to specify the artifact being produced in my "publish artifact" task based on the input variable, or is it easier/better just to produce three build pipelines?

推荐答案

是否可以在我的 Azure DevOps 构建管道发布工件"任务中有条件地设置工件名称?

Is it possible to conditionally set the artifact name in my Azure DevOps build pipeline "publish artifact" task?

恐怕没有这种开箱即用的方法可以做到这一点.如果你想有条件地设置工件名称,我们必须使用管道中的嵌套变量.

I am afraid there is no such out of box way to do that. If you want to conditionally set the artifact name, we have to use the nested variables in the pipeline.

然而,目前,嵌套变量的值(如$(CustomArtifactName_$(Build.SourceBranchName))) 在构建管道.

However, At this moment, the value of nested variables (like $(CustomArtifactName_$(Build.SourceBranchName))) are not yet supported in the build pipelines.

作为解决方法,您可以添加一个Run Inline Powershell 任务来根据输入管道变量设置变量.

As workaround, you could add a Run Inline Powershell task to set the variable based on the input pipeline variables.

在我这边,我使用 Build_SourceBranchName 作为输入管道变量.然后我在 Inline Powershell 任务中添加以下脚本:

In my side, I use Build_SourceBranchName as input pipeline variables. Then I add following scripts in the Inline Powershell task:

- task: InlinePowershell@1
  displayName: 'Inline Powershell'
  inputs:
    Script:

     $branch = $Env:Build_SourceBranchName

     if ($branch -eq "TestA5")
     {
       Write-Host "##vso[task.setvariable variable=CustomArtifactName]Red"
     }
     else
     {
       Write-Host "##vso[task.setvariable variable=CustomArtifactName]Blue"
     }

然后在 Publish Build Artifacts 任务中,我使用 drop-$(CustomArtifactName)

Then in the Publish Build Artifacts task, I set the ArtifactName with drop-$(CustomArtifactName)

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: drop'
  inputs:
    ArtifactName: 'drop-$(CustomArtifactName)'

希望这会有所帮助.

这篇关于是否可以在我的 Azure DevOps 构建管道“发布工件"中有条件地设置工件名称?任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆