git - 在 Azure Pipelines 中,当托管在 Azure Repos 中时,是否有办法在具有开放 PR 的分支上禁用 CI?

标签 git azure-devops azure-pipelines azure-repos

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

由于 Azure Repos 无法使用 pr 触发器,是否有办法实现此目的?

存储库类型:Azure Repos 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

结果:同时触发两个构建,一个单独 CI,一个PR 自动 Double triggered builds - Individual CI, and PR automated

期望:仅PR自动化构建。

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

最佳答案

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

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

以下是CI trigger的触发条件和 PR trigger .

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

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

enter image description here

然后 CI 触发器将被跳过。并且这个commit只会触发PR触发Build。

以下是equivalent commit message :

[skip ci] or [ci skip]

skip-checks: true or skip-checks:true

[skip azurepipelines] or [azurepipelines skip]

[skip azpipelines] or [azpipelines skip]

[skip azp] or [azp skip]

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

关于git - 在 Azure Pipelines 中,当托管在 Azure Repos 中时,是否有办法在具有开放 PR 的分支上禁用 CI?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66233684/

相关文章:

node.js - 如何将在 node_modules 中所做的更改提交回 git?

windows - 如何为 Windows SDK 卸载 Git?

django - Azure 应用服务托管的 Django APP 的管理面板中没有 CSS

performance - azure托管的mac管道,关于如何使其更快的建议,目前非常慢,在桌面上5分钟,在服务器上接近20

visual-studio-2015 - 使用 xUnit 适配器在 TFS/VSO Build vNext 中运行单元测试

git - 是否有针对开发人员的 SCM 公认的 "best"或规范书籍?

git - Flutter无法切换 channel

angularjs - 如何将纯 Angular 应用程序从 Visual Studio Team System 部署到 Azure 网站

.net - 通过 Azure Devops Pipeline 将 Swagger JSON 导入到 Azure 现有 API 管理

azure - 是否有一种服务连接类型和相应的任务可以方便Graph API调用?