Azure管道:如何使任务依赖于先前的任务? [英] Azure Pipelines: How to make a task dependent on a previous task?

查看:47
本文介绍了Azure管道:如何使任务依赖于先前的任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows-2019上使用Azure-Pipelines进行CI集成.在这种情况下,任务#的平均发生顺序(第一个为1).

I'm using Azure-Pipelines for my CI integration on windows-2019. Here's a scenario, the task #'s mean order in which they occur (1 being first).

在任务2中,我正在运行测试.在任务3中,无论测试成功还是失败,我都希望生成有关这些测试的报告(因此,在任务3中添加- condition:successedOrFailed()).

In task 2, I am running tests. 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).

但是,在任务1中,我正在构建存储库.如果构建失败,我不希望任何后续任务运行.但是由于任务3具有 condition:successedOrFailed(),它仍然运行并产生另一个错误.我的目标是使任务3运行,而不管任务2失败还是成功,但如果任务1失败则不运行.

However, in task 1, I am building the repo. 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. 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? Or can I stop the whole pipeline immediately if task 1 fails?

此外,对于任务1,我尝试了 continueOnError:false ,因为我认为它会停止那里的管道,但没有按照我的想法进行.任何帮助将不胜感激!

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. Any help would be much appreciated!

推荐答案

我的目标是使任务3运行,而不管任务2失败还是成功,但如果任务1失败则不运行.

My goal is to have task 3 run regardless if task 2 fails or succeeds, but not if task 1 fails.

根据您的要求,您可以连接任务3和任务1.

From your requirement, you can connect task 3 and task 1.

这是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'))

说明:

Powershell任务用于为任务1设置输出变量.当任务1成功执行时,该变量将设置值成功..此变量可用于以下任务.

The Powershell task is used to set an output variable for task 1. When task 1 success, the variable will set the value success. This variable could be used in the following tasks.

任务2中的条件取决于任务1.

The condition in task 2 depends on task 1.

任务3中的条件需要同时满足两个条件 .(1.无论成功或失败,2.自定义变量值为成功.)

The condition in task 3 needs to meet two conditions at the same time. (1. no matter success or fail , 2. The custom variable value is success).

然后,仅当任务1成功时,任务3才会运行.无论任务2失败还是成功,任务3都将运行.

Then the task 3 will run only when the task 1 success. And task 3 will run regardless if task 2 fails or succeeds.

希望这会有所帮助.

这篇关于Azure管道:如何使任务依赖于先前的任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆