gpt4 book ai didi

Azure DevOps 可选阶段

转载 作者:行者123 更新时间:2023-12-02 22:52:52 28 4
gpt4 key购买 nike

我有一个用于构建和部署项目的 yaml 管道。它部署到开发和测试。但我并不总是想部署到 tst。目前我已经通过批准解决了这个问题。当开发阶段完成时,管道等待批准。

这引入了一些问题:

  • 所有开发者每次都会收到一封电子邮件,这可能很烦人。
  • 管道会等待部署到 tst,即使不需要部署到 tst。它使等待
  • 当管道等待时,新的 ci 构建不会启动

最佳答案

如果有明确定义的方法来确定是否运行 tst 阶段,您可以 specify a custom condition在舞台上或 conditionally include the stage using an expression

指定条件

From the docs:

You can specify the conditions under which each stage, job, or stepruns. By default, a job or stage runs if it does not depend on anyother job or stage, or if all of the jobs or stages that it depends onhave completed and succeeded.

您可以通过多种方式自定义此行为,可以通过内置条件或自定义定义的条件,例如,仅当分支是 main 时才运行 tun tst 阶段:

stages:
- stage: dev
jobs:
- job: dev1
steps:
- script: echo Hello from dev!

- stage: tst
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
jobs:
- job: tst1
steps:
- script: echo Hello From tst!

当您打开管道运行时,tst 阶段仍然可见,它将被标记为已跳过

可以更改 tst 阶段下的条件以满足您的需要(它可以包括 variablesparameters 甚至 output from previous stages

条件表达式

From the docs:

You can use if, elseif, and else clauses to conditionally assignvariable values or set inputs for tasks. You can also conditionallyrun a step when a condition is met.

条件插入仅适用于模板语法,该语法在编译管道 yaml 时(即管道启动之前)进行评估。因此它无法评估先前步骤的输出。在下面的示例中,如果分支不是 main

,则在实例化管道(并编译模板)时,tst 阶段将从管道运行中完全删除
stages:
- stage: dev
jobs:
- job: dev1
steps:
- script: echo Hello from dev!
- ${{ if eq(variables['Build.SourceBranch'], 'refs/heads/main') }}:
- stage: tst
jobs:
- job: tst1
steps:
- script: echo Hello From tst!

关于Azure DevOps 可选阶段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69808639/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com