在 Azure Pipelines 中,当托管在 Azure Repos 中时,是否可以通过开放 PR 禁用分支上的 CI?

问题描述

我们有一个用例,其中我们的代码完全托管在 Azure DevOps(Pipelines、Repos 等)中。我们需要构建和部署我们的“完整”构建/部署流程来部署无服务器功能。理想情况下,我们想要的是在 PR 打开和更新时的单个构建/部署过程。我们有一个构建验证策略,当 PR 接受另一个 Individual CI 时,我们希望忽略 push 构建,因为 Build Validation 策略应该取代 trigger 块。

由于 pr 触发器不适用于 Azure Repos,所以有没有办法实现这一点?

存储库类型:Azure 存储库 Git

# The pipeline will fail if a branch is not either 'main' or 'something/12345-something'
trigger:
  paths:
    exclude:
      - azure-pipelines-cleanup.yaml
      - docs
      - README.md

name: $(SourceBranchName).$(Rev:r)_$(Build.RequestedFor)

resources:
  repositories:
    - repository: pipeline
      type: git
      name: <Org Obscured>/infra-pipeline
      ref: feature/212242-pipeline-housecleaning # this is pipeline branch ref,should be main unless testing pipeline changes

# This extends a template from the central pipeline repo
extends:
  template: service-pipeline-template.yaml@pipeline
  parameters:
    appName: starter
    publishSdk: true

Build Validation setup

结果:两个构建,一个 Invididual CI一个 PR automated 同时触发

Double triggered builds - Individual CI,and PR automated

期望:只有 PR automated 构建。

这不是条件表达式本身的问题,除非有一种方法可以完全禁用触发器块,同时仍然在 PR 中运行完整的管道。我不认为有一种方法可以在 ADO 中运行服务器端 git 钩子。

解决方法

恐怕没有这样的方法可以仅在 PR 触发器存在时禁用 CI 触发器。

在 Azure Devops 中,CI 触发器和 PR 触发器是两个独立的触发器。如果同时满足触发条件,管道将被触发两次。

这里是CI triggerPR trigger的触发条件。

但是,有一种解决方法可以达到您想要的状态。

您可以在推送更改时在提交消息中添加 [skip ci]

enter image description here

然后将跳过 CI 触发器。而这次提交只会触发 PR 触发器 Build。

以下是equivalent commit message

[跳过 ci] 或 [跳过 ci]

skip-checks: true 或 skip-checks:true

[跳过 azurepipelines] 或 [跳过 azurepipelines]

[跳过 azpipelines] 或 [跳过 azpipelines]

[跳过 azp] 或 [跳过 azp]

您也可以在 Our UserVoice site 中提交功能请求。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...