Forum Discussion

marijarasojo's avatar
marijarasojo
Copper Contributor
Oct 03, 2024

Can't trigger a pipeline hosted in RepoA when a commit is pushed to RepoB

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: |
        $headerValue = "Authorization: Basic " + [Convert]::ToBase64String([System.Text.Encoding]::UTF8. GetBytes(":" + $env:PAT))

git -c http.extraheader="$headerValue" clone $(REPO_URL)
    env:
      PAT: $(PAT) 

#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 in Azure DevOps

- The Personal Access Token (PAT) is correctly configured, and the pipeline passes when executed manually.

- The YAML is hosted in the default branch (master) of Repo B

 

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

 

Many thanks in advance! 

2 Replies

  • kareem_t's avatar
    kareem_t
    Copper Contributor
    The main reason your pipeline isn't triggering is because of the version of Azure DevOps Server you're using. You're on TFS Version Dev17.M153.5, which corresponds to Azure DevOps Server 2019 Update 1. In this version, resource triggers for repositories aren't supported in YAML pipelines. This feature was actually introduced later, in Azure DevOps Server 2020.

    To resolve the issue, you might consider:

    1. Upgrading to Azure DevOps Server 2020 or later: This would allow you to use resource triggers in your YAML pipelines.
    2. Moving your pipeline YAML file to Repo B: This way, commits pushed to Repo B would directly trigger the pipeline.
    3. Setting up a service hook or using the REST API: As a workaround, you can trigger the pipeline from Repo B using these methods.

    Hope this helps! Let me know if you have any questions or need more assistance.
  • marijarasojo 

     

    Try this, please make sure you are fully understanding before apply:

     

    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: |
    $headerValue = "Authorization: Basic " + [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(":" + $env:PAT))
    git -c http.extraheader="$headerValue" clone $(REPO_URL)
    env:
    PAT: $(PAT)

    #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

Resources