Azure DevOps。当存储库 B 中完成提交时,无法触发存储库 A 中的管道

问题描述 投票:0回答:1

我正在使用版本 Dev17.M153.5 (TFS),并且我有两个存储库:我的源代码托管在 Repo B 中,我的管道托管在 Repo A 中以保持职责分离。

我的目标是每当提交推送到 Repo B 时,Repo A 中的管道就会自动运行。以下是我当前的设置:

# MY MAIN PIPELINE IN REPO A:
trigger: none
resources:
  repositories:
    - repository: RepoB
      type: git
      name: Project/RepoB
      ref: develop
      trigger:
        branches:
          include:
            - develop
            - master

pool:
  name: 'Test'

variables:
  REPO_URL: 'https://tfs.company.com/company/Project/_git/RepoB'

steps:
  - task: PowerShell@2
    displayName: 'Configurar encabezado GIT_AUTH_HEADER con PAT'
    inputs:
      targetType: 'inline'
      script: |
        # Crear el encabezado de autenticación en formato Base64
        $headerValue = "Authorization: Basic " + [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(":" + $env:PAT))

        git -c http.extraheader="$headerValue" clone $(REPO_URL)
    env:
      PAT: $(PAT)  # El PAT como variable de entorno secreta

    #Templates
  - ${{ if eq(variables['Build.SourceBranch'], 'refs/heads/master') }}:
    - template: pipeline-master.yml

  - ${{ if eq(variables['Build.SourceBranch'], 'refs/heads/develop') }}:
    - template: pipeline-develop.yml

问题: 当在开发或主控上将提交推送到存储库 B 时,此管道不会自动触发。我无法使用结账,因为它只接受自我或不接受。但是,Repo B 已成功克隆,并且如果我手动触发它,管道运行良好

其他注意事项:

  • 构建服务在两个存储库中将“读取和贡献”权限设置为“允许”。
  • Repo A 和 Repo B 都是同一个项目的一部分。
  • 个人访问令牌(PAT)配置正确,手动执行时管道通过。

enter image description here

问题: 为什么管道没有自动触发,以及如何确保它在提交推送到 Repo B 时运行?

更新

我读过很多关于在默认分支中编译 YAML 文件的警告文章。我在 master 中编译它,这是我的默认分支,但仍然不起作用

提前非常感谢!

git azure azure-devops tfs azure-pipelines
1个回答
0
投票

根据您的描述,您使用的是Azure DevOps Server 2019(版本:Dev17.M153.5)。

请参阅此文档:Azure DevOps Server 2019 - resources.repositories.repository 定义

repositories:
- repository: string # Required as first property. Alias for the repository.
  endpoint: string # ID of the service endpoint connecting to this repository.
  name: string # repository name (format depends on 'type'; does not accept variables).
  type: string # Type of repository: git, github, githubenterprise, and bitbucket.
  ref: string # ref name to checkout; defaults to 'refs/heads/main'. The branch checked out by default whenever the resource trigger fires. Does not accept variables.

问题的原因是Azure DevOps Server 2019不支持Repo资源触发器。因此,即使设置了Repo资源触发,也不会触发成功。

要解决此问题,您需要升级 Azure DevOps 服务器 2020 或更高版本。从 Azure DevOps Server 2020 开始支持此功能。

© www.soinside.com 2019 - 2024. All rights reserved.