Post Azure Pipelines 中的取消任务

Post cancellation task in Azure Pipelines

我们有一个场景,一旦我们在 Azure DevOps 中手动取消管道,我们需要终止特定进程 (exe)。我们想知道如何在 YAML post 取消中触发任务,以实现此目的。

您可以添加终止进程的步骤,并仅在管道被取消时将其配置为 运行 - 使用 custom condition:

condition: eq(variables['Agent.JobStatus'], 'Canceled')

请尝试以下方法:

  1. 如果您的管道中有多个作业,请确保 运行 将任务交给 terminate the particular process (exe) 的作业在所有其他作业完成处理后得到处理(SucceededFailedCanceled)。您可以使用 'dependsOn' 键来设置作业的执行顺序。有关更多详细信息,请参阅“Dependencies”。

    那么,正如@ShaykiAbramczyk所说,在terminates the particular process (exe)的作业上,你可以使用'condition ' 键指定作业 运行s 的条件。有关更多详细信息,请参阅“Conditions”。

    jobs:
    . . .
    - job: string
      dependsOn: string
      condition: eq(variables['Agent.JobStatus'], 'Canceled')
    
  2. 如果您的管道中只有一项作业,请确保 terminate the particular process (exe) 的任务是该作业的最后一步。您需要将此任务放在此作业的步骤列表的底部。

    然后还需要在任务上指定条件到terminate the particular process (exe)

    • 如果在此步骤中使用'condition'键,则此步骤将始终列出并显示在作业中运行,不管是否跳过

      steps:
      - step: string
         condition: eq(variables['Agent.JobStatus'], 'Canceled')
      
    • 如果在步骤上使用'if'语句,只有当'if'时,该步骤才会在作业中列出并显示运行条件满足再到运行这一步。如果不满足条件,则跳过该步骤,则此步骤会隐藏在job中运行.

      steps:
      - ${{ if eq(variables['Agent.JobStatus'], 'Canceled') }}:
         - step: string