是否可以在我的Azure DevOps构建管道中有条件地设置工件名称?任务? [英] Is it possible to conditionally set the artifact name in my Azure DevOps build pipeline "publish artifact" task?
问题描述
我想知道是否可以在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 任务中,将ArtifactName
设置为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屋!