条件手动验证步骤在Azure DevOps管道



使用Azure DevOpsManualValidation任务,该任务可以根据管道中先前定义的变量有条件地运行吗?

作业接受enabled参数,但似乎必须硬编码为true或false。

- stage: Approve_${{ targetPath.stageName }}_${{ parameters.planEnvironment }}
jobs:
- job: waitForValidation
displayName: Wait for external validation
pool: server
timeoutInMinutes: ${{ parameters.timeoutInMinutes }}
steps:
- task: ManualValidation@0
environment: development ## environment not accepted here
#enabled: $[destroy] ## Unexpected value '$[destroy]'",
#enabled: $(destroy) ## fails - syntax error (does not like this to be a var)
# manually setting true/false works
#enabled: true
#enabled: false
inputs:
notifyUsers: |
alert@test.com
instructions: 'Please validate the build configuration and resume'
onTimeout: 'reject'

enabled控制选项为booleantype,表示是否运行此步骤,默认为" true "。如果您想使用enabled控件选项来限制ManualValidation步骤,您可以检查以下语法:

variables:
- name: destroy
value: true

jobs:  
- job: waitForValidation
displayName: Wait for external validation  
pool: server    
timeoutInMinutes: 4320 # job times out in 3 days
steps:   
- task: ManualValidation@0
timeoutInMinutes: 1440 # task times out in 1 day
enabled: ${{ variables.destroy }}
inputs:
notifyUsers: |
test@test.com
example@example.com
instructions: 'Please validate the build configuration and resume'
onTimeout: 'resume'

否则可以指定@Shayki Abramczyk提到的步骤下的条件。

您可以在每个任务中使用自定义条件:

- task: ManualIntervention@8
inputs:
instructions: 'test'
condition: and(succeeded(), eq(variables['VariableName'], 'VariableValue'))

另一种选择是使用模板参数条件,使舞台、作业或任务在不需要时消失。也就是说,当对管道代码进行预处理时,使用条件来避免将项插入到管道运行时实际运行的扩展的yaml文件中。

- ${{ if ne(parameters.EnvironmentName, 'Dev') }}:
- stage: Approve_${{ targetPath.stageName }}_${{ parameters.planEnvironment }}
jobs:
- job: waitForValidation
displayName: Wait for external validation
pool: server
timeoutInMinutes: ${{ parameters.timeoutInMinutes }}
steps:
- task: ManualValidation@0
environment: development ## environment not accepted here
inputs:
notifyUsers: |
alert@test.com
instructions: 'Please validate the build configuration and resume'
onTimeout: 'reject'

上面的例子使用了一个名为EnvironmentName的管道模板参数。您可以使用一些变量,正如Azure DevOps的预定义变量文档中所解释的那样(参见"模板中可用?")。表列).

请注意,通过dependsOn功能引用此阶段(或作业,如果您将条件置于作业上)的任何后续阶段也需要使用相同的逻辑使dependsOn消失。

更多信息请参见条件插入官方文档。

最新更新