Search code examples
azure-devopsyamlazure-pipelines

How to trigger another pipeline in different repository using azure yaml


I need to trigger pipeline (present in different repository and branch) using below yaml file. The resources parameter is not working. Should I create different yml file for "resources"?

resources:
  repositories:
    - repository: <reponame>
      type: github
      name: <organization/reponame>
      ref: <branchname>

stages:
  - stage: "PipelineTesting"
    dependsOn: [Build]
    jobs:
      - job: PipelineTesting
        displayName: Trigger Pipeline in repo <reponame> and branch <branchname>
        steps:
          - checkout: none # Skip checking out source code
          - script: echo "Triggering pipeline in <reponame> and  <branchname>"
            displayName: 'Trigger <reponame> Pipeline'

I am expecting to trigger new pipeline present in different repository.


Solution

  • The typical process is to make these changes in the pipeline you are wanting to trigger. Is that possible for you? If so, you declare all this information in the resources section like so:

    resources:
      pipelines:
      - pipeline: pipelineResourceName
        source: yourFolder\yourTriggeringPipeline.yml # Name of the pipeline file that triggers this pipeline.
        trigger:
          branches:
            include: 
            - main # This allows you to specify the pipeline to only trigger from specific branch runs.
    

    See the documentation here for more information: https://learn.microsoft.com/en-us/azure/devops/pipelines/process/pipeline-triggers?view=azure-devops