Azure DevOps Server 2019 不支持参数,任何想法如何
可以加这样的条件吗?
是的,根据this ticket Azure DevOps Server 2019 不能很好地支持参数。所以我建议你可以通过变量而不是参数尝试条件作业/步骤,以获取有关Conditions 语法的更多详细信息。
由于 Azure Devops Server 目前不支持参数,因此不建议在您的方案中使用模板。 (变量不能用于条件模板)。您可以直接在 azure-pipeline.yml 文件中展开这些步骤,如下所示:
jobs:
- job: build
pool:
name: Default
steps:
- task: CmdLine@2
inputs:
script: 'echo This is first build task'
condition: {Add your custom condition here in Step level.}
- task: CmdLine@2
inputs:
script: 'echo This is second build task'
- job: test
condition: {Add your custom condition here in Job level.}
pool:
name: Default
steps:
- task: CmdLine@2
inputs:
script: 'echo This is first test task'
- task: CmdLine@2
inputs:
script: 'echo This is second test task'
您可以在 Job/Step 级别添加条件来确定一个 Job/Step 是否会运行。
两个不同方向的示例:
1.在yaml中定义变量(硬编码):
variables:
WhetherToRunCmd:true
jobs:
- job: build
pool:
name: Default
steps:
- task: CmdLine@2
inputs:
script: 'echo This is first build task'
condition: ne(variables.WhetherToRunCmd,false)
- task: CmdLine@2
inputs:
script: 'echo This is second build task'
那么第一个cmd任务会默认运行,当我们把WhetherToRunCmd:true改成WhetherToRunCmd:false时会跳过运行。
2.使用queue time variable,不需要在yml文件中定义变量:
编辑 yaml 管道并选择变量:
定义变量WhetherToRunJob并在队列时启用可设置:
然后在 yml 中使用类似这样的东西:
- job: test
condition: ne(variables.WhetherToRunJob,false)
那么这个job会默认运行,当我们使用Queue with parameters option将值改为false时就跳转运行:
我认为variables+condition 也可以满足您有条件地运行步骤/作业的需求。您也可以根据需要修改条件,例如 and(succeed(),eq(...)...) 或什么。