简体   繁体   English

Azure 管道:如何使任务依赖于先前的任务?

[英]Azure Pipelines: How to make a task dependent on a previous task?

I'm using Azure-Pipelines for my CI integration on windows-2019.我正在使用 Azure-Pipelines 在 windows-2019 上进行 CI 集成。 Here's a scenario, the task #'s mean order in which they occur (1 being first).这是一个场景,任务 # 的平均发生顺序(1 是第一个)。

In task 2, I am running tests.在任务 2 中,我正在运行测试。 In task 3, I want to generate a report on these tests, regardless if the tests succeeded or failed (thus adding - condition: succeededOrFailed() to task 3).在任务 3 中,我想生成有关这些测试的报告,无论测试是成功还是失败(因此将 - condition: succeededOrFailed()添加到任务 3)。

However, in task 1, I am building the repo.但是,在任务 1 中,我正在构建存储库。 If the build fails, I don't want any subsequent tasks to run.如果构建失败,我不希望任何后续任务运行。 But since task 3 has condition: succeededOrFailed() , it still runs and produces another error.但由于任务 3 condition: succeededOrFailed() ,它仍然运行并产生另一个错误。 My goal is to have task 3 run regardless if task 2 fails or succeeds, but not if task 1 fails.我的目标是让任务 3 无论任务 2 失败还是成功都运行,但如果任务 1 失败则不会。

I'm not sure the best way to handle this.我不确定处理这个问题的最佳方法。 Is it possible to make task 3 dependent on task 2?是否可以使任务 3 依赖于任务 2? Or can I stop the whole pipeline immediately if task 1 fails?或者如果任务 1 失败,我可以立即停止整个管道吗?

Also, for task 1, I tried continueOnError: false because I thought it would stop the pipeline there, but it didn't do what I thought.另外,对于任务 1,我尝试了continueOnError: false ,因为我认为它会在那里停止管道,但它并没有按照我的想法做。 Any help would be much appreciated!任何帮助将非常感激!

My goal is to have task 3 run regardless if task 2 fails or succeeds, but not if task 1 fails.我的目标是让任务 3 无论任务 2 失败还是成功都运行,但如果任务 1 失败则不会。

From your requirement, you can connect task 3 and task 1.根据您的要求,您可以连接任务 3 和任务 1。

Here is the Yaml template:这是 Yaml 模板:

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: task1
...


- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      # Write your PowerShell commands here.

      Write-Host "##vso[task.setvariable variable=task.A.status]Success"      
  condition: succeeded()

- task: task2
 ...
  condition: succeeded()

- task: task 3
....
  condition: and (succeededOrFailed(), eq(variables['task.A.status'], 'success'))

Explaination:说明:

The Powershell task is used to set an output variable for task 1. When task 1 success, the variable will set the value success . Powershell task用于为任务 1 设置一个output variable 。当任务 1 成功时,该变量将设置值success This variable could be used in the following tasks.此变量可用于以下任务。

The condition in task 2 depends on task 1.任务 2 中的条件取决于任务 1。

The condition in task 3 needs to meet two conditions at the same time .任务3中的条件需要同时满足两个条件。 (1. no matter success or fail, 2. The custom variable value is success). (1.无论成功或失败,2.自定义变量值为success)。

Then the task 3 will run only when the task 1 success.然后任务 3 将仅在任务 1 成功时运行。 And task 3 will run regardless if task 2 fails or succeeds.无论任务 2 失败还是成功,任务 3 都会运行。

Hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM