是否可以基于变量创建其他管道步骤? [英] Is it possible to create additional pipeline steps based on a variable?
问题描述
Azure Devops YAML管道中是否可以基于某些变量数据动态创建其他步骤(而无需创建自己的插件)
Is it possible in Azure Devops YAML pipelines to dynamically create additional steps based on some variable data (without creating our own plugin)
问题是我想遍历几个目录,但是我不想只一步将它们全部包起来,因为这会使扫描到一个错误变得更加困难.
The thing is I see that I want to iterate through several directories, but I don't want to just lump it all in a single step since it makes it harder to scan through to find an error.
推荐答案
是否可以在Azure Devops YAML管道中动态创建基于一些可变数据的其他步骤(无需创建我们自己的插件)
Is it possible in Azure Devops YAML pipelines to dynamically create additional steps based on some variable data (without creating our own plugin)
否,Yaml管道(azure-pipeline.yml)受版本控制.因此,您想要的(对于您的原始标题)是在执行管道时将更改动态提交到 azure-pipeline.yml
文件.不建议这样做.
No, Yaml pipelines(azure-pipeline.yml) are under Version Control. So what you want (for your original title) is to dynamically commit changes to the azure-pipeline.yml
file when executing the pipeline. That's not a recommended workflow.
1.相反,您可以考虑使用 Azure Devops条件可动态启用/禁用其他步骤.
1.Instead you can consider using Azure Devops Conditions to dynamically enable/disable the additional steps.
-
或使用某些预定义的变量:
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
2.如果您不使用条件,则可以检查条件模板,如上面的 Simon 所建议.
2.If you're not using Conditions, you can check conditional template as Simon suggests above.
Also, both #1 and #2 can work with new feature runtime parameters.
3.但是,如果您要表示的动态变量来自 components的结果= ls -1 $(Pipeline.Workspace)/components
命令的结果,则上述提示将不起作用情况.为此,您可以尝试如下操作:
3.However, if the dynamic variable you mean comes from the result of components = result of ls -1 $(Pipeline.Workspace)/components
command, above tips won't work for this situation. For this you can try something like this:
- 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')
这篇关于是否可以基于变量创建其他管道步骤?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!