Azure Devops YAML管道中是否可以基于某些变量数据动态创建其他步骤(而无需创建自己的插件)
问题是我想遍历几个目录,但是我不想只一步将它们全部包起来,因为这会使扫描到一个错误变得更加困难。
答案 0 :(得分:0)
可以使用if statement有条件地包含步骤。
我认为同一页上的extending a template示例可以很好地说明如何遍历list参数并基于每个值创建/运行步骤。
答案 1 :(得分:0)
在Azure Devops YAML管道中是否可以动态创建 基于一些可变数据的其他步骤(无需创建我们自己的 插件)
否,Yaml管道(azure-pipeline.yml)受版本控制。因此,您想要的(对于原始标题)是在执行管道时将更改动态提交到azure-pipeline.yml
文件。不建议这样做。
1。相反,您可以考虑使用Azure Devops Conditions动态启用/禁用其他步骤。
Use the output variable from a job in a condition in a subsequent job
或使用一些predefined variables:
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
2。如果您不使用条件,则可以按照上述 Simon 的建议检查conditional template。
#1和#2都可以使用新功能runtime parameters。
3。但是,如果您指的动态变量来自components = result of ls -1 $(Pipeline.Workspace)/components
命令的结果,则上述技巧在这种情况下将不起作用。为此,您可以尝试如下操作:
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
# Write your PowerShell commands here.
# some logic to run `components = result of ls -1 $(Pipeline.Workspace)/components` and determine whether to set the WhetherToRun=true.
'Write-Host "##vso[task.setvariable variable=WhetherToRun]True"'
- task: CmdLine@2
inputs:
script: |
echo Hello world
condition: eq(variables['WhetherToRun'], 'True')