'Azure DevOps - Trigger another pipeline
I got two pipelines in my project, one for test and one for build. The reason for this is that the tests need to be run on an self hosted agent to be able to run integration tests.
I don't want to run the build pipeline if the tests are failing. This is my configuration:
Test (Pipeline name)
name: Test
trigger:
  - azure-pipelines
pool:
  vmImage: "windows-latest"
steps:
  - script: echo Test pipeline
Build (Pipeline name)
name: Build
trigger: none
resources:
  pipelines:
    - pipeline: test
      source: Test
      trigger: true
pool:
  vmImage: "windows-latest"
steps:
  - script: echo Build pipeline
The Test pipeline is running as expected but the Build pipeline never gets triggered even if I run it in the cloud as in the example above. Anyone see what the problem is?
Solution 1:[1]
It is possible to call another pipeline as shown in the other answer but to start a different agent OS, I would suggest using a Multistage pipeline or Strategy Matrix.
Each stage can run with its own VM or Agent pool.
Here is an example:
trigger:
- main
stages:  
- stage: Build  
  pool:
    vmImage: ubuntu-latest
  jobs:  
  - job: BuildJob  
    steps:  
    - script: echo Building
- stage: TestWithLinux
  dependsOn: Build
  pool:
    vmImage: ubuntu-latest
  jobs:  
  - job: Testing
    steps:
    - script: echo Test with Linux OS
- stage: TestWithWindows
  dependsOn: Build
  pool:
    vmImage: windows-latest
  jobs:  
  - job: Testing
    steps:
    - script: echo Test with Windows OS
- stage: Final
  dependsOn: [TestWithLinux,TestWithWindows]
  pool:
    vmImage: ubuntu-latest
  jobs:  
  - job: FinalJob
    steps:
    - script: echo Final Job
You can replace vmImage: xxx with your own hosted Agent like:
pool: AgentNameX
And the final result would look like this:
Or It is possible to use a strategy with the matrix. Let's say we have a code that should be run on 3 different agents, we can do the following:
jobs:  
- job:
  strategy:
    matrix:
      Linux:
        imageName: 'ubuntu-latest'
      Mac:
        imageName: 'macOS-latest'
      Windows:
        imageName: 'windows-latest'
  pool:
    vmImage: $(imageName)
  steps:
  - powershell: |
      "OS = $($env:AGENT_OS)" | Out-Host
    displayName: 'Test with Agent'
It can work as a stand-alone or in multi-stages as well as shown in the image:
Here is a list of supported hosted agents.
Disclaimer: I wrote 2 articles about this in my personal blog.
Solution 2:[2]
Make sure you use the correct pipeline name. I would also suggest adding project inside resources pipeline.
For example I have a pipeline named first.
first.yml
 trigger:
 - none
 pr: none
 pool:
   vmImage: ubuntu-latest
 steps:
 - script: echo Running the first pipeline, should trigger the second.
   displayName: 'First pipeline'
second.yml
trigger:
- none
pool:
  vmImage: ubuntu-latest
resources:
  pipelines:
  - pipeline: first
    source: first
    project: test-project
    trigger: true # Run second pipeline when the run of the first pipeline ends
steps:
- script: echo this pipeline was triggered from the first pipeline
  displayName: 'Second pipeline'
    					Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source | 
|---|---|
| Solution 1 | |
| Solution 2 | GeralexGR | 


