You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

共享代理池的Azure Pipelines互抢代理致构建被取消问题排查

DevOps Server Gated Check-in 构建互抢代理问题排查

问题描述

为不同分支配置了多个Gated Check-in流水线,均使用同一个仅含单个Build Agent的Agent Pool。当分支A构建进行时提交分支B代码,A的构建会立即被取消(提示The Operation Was Canceled错误)并启动B的构建,反之亦然;同分支重复提交则会正常排队等待。这导致Gated Check-in构建因他人在构建完成前提交其他分支代码而失败。该问题在从TFS 2018(待确认)迁移至DevOps 2020后出现,旧版本无此问题,怀疑遗漏了关键配置。

相关YAML配置

name: $(date:yyyyMMdd)$(rev:.r)
resources:
  repositories:
  - repository: self
    type: git
    ref: $/ProjectName/Trunk
jobs:
- job: Phase_1
  displayName: Phase 1
  cancelTimeoutInMinutes: 1
  pool:
    name: Pool 2
  steps:
  - checkout: self
    clean: true
  - task: NuGetToolInstaller@0
    displayName: Use NuGet 4.4.1
    enabled: False
    inputs:
      versionSpec: 4.4.1
  - task: NuGetToolInstaller@1
    displayName: Use NuGet 5.11.x
    inputs:
      versionSpec: 5.11.x
  - task: NuGetInstaller@0
    name: NuGetInstaller_1
    displayName: NuGet restore **\*.sln
    enabled: False
    inputs:
      solution: '**\*.sln'
      noCache: true
      nuGetPath: $(NuGetPath)
  - task: NuGetCommand@2
    displayName: NuGet restore
  - task: VSBuild@1
    name: VSBuild_2
    displayName: Build solution **\*.sln
    enabled: False
    inputs:
      platform: $(BuildPlatform)
      configuration: $(BuildConfiguration)
      clean: true
      msbuildArchitecture: x64
  - task: MSBuild@1
    displayName: Build solution **/*.sln
    inputs:
      msbuildLocationMethod: location
      msbuildLocation: C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\MSBuild.exe
      platform: $(BuildPlatform)
      configuration: $(BuildConfiguration)
      msbuildArguments: /p:OutDir=$(build.artifactstagingdirectory) /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true
...

配置截图说明

触发器设置

  • 已启用Gated Check-in触发器
  • 绑定了对应分支路径
  • 未启用其他类型触发器

选项设置

  • 配置了构建超时时间
  • 未显式勾选全局取消构建类选项

问题原因及解决方案

核心原因

不同分支的Gated构建互抢代理并取消已有构建,本质是流水线的构建取消策略未按分支隔离。DevOps Server 2020中,若配置不当,不同分支的独立流水线会共享同一取消规则,导致新构建直接终止其他分支的运行中构建。

具体排查及修复步骤

  1. 调整流水线队列取消策略
    打开流水线编辑界面,进入「选项」标签页,找到「构建队列行为」区域:

    • 将「当新构建排队时取消正在运行的构建」设置为仅取消同一分支的正在运行的构建,而非全局取消所有运行中构建。
  2. 检查Gated Check-in专属取消设置
    进入「触发器」->「Gated Check-in」标签页:

    • 若存在「取消此存储库中正在运行的其他构建」选项,直接取消勾选,避免跨分支构建互相终止。
  3. 验证Agent Pool配置
    进入Agent Pool设置页面:

    • 确认「最大并发作业数」为1(匹配单个Agent的资源限制),同时检查无全局级别的构建取消规则配置。
  4. 确认流水线分支隔离
    确保每个分支对应的流水线独立配置,触发器仅绑定目标分支,避免不同分支的流水线共享触发规则导致冲突。


内容的提问来源于stack exchange,提问作者guildsbounty

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 02:45:11