Search code examples
gitazureazure-devopstfsazure-pipelines

Azure DevOps. Can't trigger a pipeline in Repo A when a commit is done in repo B


I’m using Version Dev17.M153.5 (TFS), and I have two repositories: my source code is hosted in Repo B, and my pipelines are hosted in Repo A to keep responsibilities separated.

My goal is for the pipeline in Repo A to automatically run whenever a commit is pushed to Repo B. Below is my current setup:

# 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

The Issue: This pipeline does not trigger automatically when a commit is pushed to Repo B on either develop or master. I cannot use checkout because it only accepts self or none. However, Repo B is successfully cloned, and the pipeline runs fine if I trigger it manually

Additional Considerations:

  • Build services have "Read and Contribute" permissions set to "Allow" in both repositories.
  • Both Repo A and Repo B are part of the same project.
  • The Personal Access Token (PAT) is correctly configured, and the pipeline passes when executed manually.

enter image description here

Question: Why is the pipeline not triggering automatically, and how can I ensure it runs whenever a commit is pushed to Repo B?

Update

I have read many posts warning about compiling the YAML file in the default branch. I am compiling it in master, which is my default branch, and still doesn't work

Many thanks in advance!


Solution

  • Based on your description, you are using Azure DevOps Server 2019(version: Dev17.M153.5).

    Refer to this doc: Azure DevOps Server 2019 - resources.repositories.repository definition

    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.
    

    The cause of the issue is that Azure DevOps Server 2019 doesn't support Repo Resources trigger. Therefore, even if you set the Repo resources trigger, it will not be triggered successfully.

    To solve this issue, you need to upgrade your Azure DevOps server 2020 or higher. This feature will be supported starting from Azure DevOps Server 2020.