skip to Main Content

I have my own pipeline p-A with repository r-A, and pipeline p-B with another repo r-B.

I want to update the pipeline script for p-A only, to trigger the p-B actively, without any modification in p-B.

Below is the yaml pipeline script for p-B, which is already set up to run with schedule

pool:
  name: 'workflow_test_pool'

schedules:
   - cron: "0 19 * * *"
     displayName: run test every day at 8PM CET
     branches:
       include:
         - main
     always: true

trigger: none

jobs:
  - job:
    timeoutInMinutes: 30
    steps:
      - script: |
          python -m pytest tests/ -s
        displayName: 'Run the test'
        

below is the pipeline script main.yaml for p-A

pool:
  name: 'workflow_test_pool'

stages:
  #########################
  - template: pipeline2/p1.yaml


  ############################
  - template: pipeline2/p2.yaml
    parameters:
      dependsOn:
        - FirstPipeline

so the question is, how to trigger the pipeline p-B in pipeline2/p2.yaml(from p-A)?

2

Answers


  1. You can create PowerShell script task as the last step of the pipeline to trigger pipeline p-B through REST API. You will have to maintain Personal Access Token, ideally as secret variable.

    REST API call you will use:
    https://learn.microsoft.com/en-us/rest/api/azure/devops/pipelines/runs/run-pipeline?view=azure-devops-rest-7.1

    Detailed step-by-step guide:
    https://blog.geralexgr.com/cloud/trigger-azure-devops-build-pipelines-using-rest-api

    Login or Signup to reply.
  2. Azure DevOps supports multiple repositories checkout, you can just reference resources function in your YAML script and call another repository to trigger from the pipeline.

    YAML code :-

    # Starter pipeline
    
    # Start with a minimal pipeline that you can customize to build and deploy your code.
    
    # Add steps that build, run tests, deploy, and more:
    
    # https://aka.ms/yaml
    
      
    
    pool:
    
    vmImage: ubuntu-latest
    
      
    
    workspace:
    
    clean: all
    
      
    
    resources:
    
    repositories:
    
    - repository: repo_a
    
    type: git
    
    name: InternalProjects/repo_a
    
    trigger:
    
    - main
    
    - release
    
      
    
    - repository: repo_b
    
    type: git
    
    name: InternalProjects/repo_b
    
    trigger:
    
    - main
    
    steps:
    
    - checkout: repo_a
    
    - checkout: repo_b
    
      
    
    - script: dir $(Build.SourcesDirectory)
    
    

    I am running this pipeline from repo_a and the repo_a and repo_b both ran successfully like below:-

    Output :-

    enter image description here

    You can directly run any task from pipeline with multiple repositories like below:-

    # Starter pipeline
    
    # Start with a minimal pipeline that you can customize to build and deploy your code.
    
    # Add steps that build, run tests, deploy, and more:
    
    # https://aka.ms/yaml
    
      
    
    pool:
    
    vmImage: ubuntu-latest
    
      
    
    workspace:
    
    clean: all
    
      
    
    resources:
    
    repositories:
    
    - repository: repo_a
    
    type: git
    
    name: InternalProjects/repo_a
    
    trigger:
    
    - main
    
    - release
    
      
    
    - repository: repo_b
    
    type: git
    
    name: InternalProjects/repo_b
    
    trigger:
    
    - main
    
    steps:
    
    - checkout: repo_a
    
      
    
    - checkout: repo_b
    
    - task: AzureCLI@2
    
    inputs:
    
    azureSubscription: 'Subscription-name(sub-id)'
    
    scriptType: 'bash'
    
    scriptLocation: 'inlineScript'
    
    inlineScript: 'az resource list --location uksouth'
    
    

    Output:-

    enter image description here

    References :-

    Check out multiple repositories in your pipeline – Azure Pipelines | Microsoft Learn

    Trigger azure Devops pipeline from another repository – GeralexGR

    Multiple Repositories in a Single Azure Pipeline – DEV Community 👩‍💻👨‍💻

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search