0

Azure Devops, yaml pipeline, trigger particular stage by PR.

Is it possible to trigger a particular stage by different PRs completion (not by creating a build or PR and then trigger another build pipeline)? Example below, if I update we.json and merge a PR to my Azure repository, I want PR to trigger my pipeline and particularly the stage Deploy-we only, and not trigger Deploy-ne.

trigger:
  branches: 
    include: 
    - main
  paths:
    include: 
    - arm/we.json
    - arm/ne.json

pool:
  vmImage: ubuntu-latest

stages:
- stage: we
  condition: xxx
  jobs:
  - job: Deploy-we
    steps:
    - task: AzureResourceManagerTemplateDeployment@3
      inputs:
        deploymentScope: 'Resource Group'
        azureResourceManagerConnection: 'xxx'
        subscriptionId: 'xxx'
        action: 'Create Or Update Resource Group'
        resourceGroupName: 'xxx-we-rg'
        location: 'West Europe'
        templateLocation: 'Linked artifact'
        csmFile: 'arm/we.json'
        csmParametersFile: 'we-param.json'
        deploymentMode: 'Incremental'

- stage: ne
  condition: xxx
  jobs:
  - job: Deploy-ne
    steps:
    - task: AzureResourceManagerTemplateDeployment@3
      inputs:
        deploymentScope: 'Resource Group'
        azureResourceManagerConnection: 'xxx'
        subscriptionId: 'xxx'
        action: 'Create Or Update Resource Group'
        resourceGroupName: 'xxx-ne-rg'
        location: 'North Europe'
        templateLocation: 'Linked artifact'
        csmFile: 'arm/ne.json'
        csmParametersFile: 'ne-param.json'
        deploymentMode: 'Incremental'

Note, this is not a question how to trigger a 'release pipeline'.

NewUser
  • 25
  • 1
  • 7
  • The easy solution would be to create two different pipelines, one for `we` and one for `ne` ? – Thomas Apr 25 '22 at 10:06
  • You can also have a look at this post, it explains how to get the files that have changed: https://stackoverflow.com/questions/65088433/how-to-get-only-changed-files-using-azure-devops-pipelines. – Thomas Apr 25 '22 at 10:09
  • @Thomas Thank you for suggestions - ideally we prefer one pipeline with around 12 stages, instead of 12x separate pipelines. But it seems there is no out of the box MS solution for this kind of idea, as triggers paths can not be used in the steps or stages condition. Unless someone else has ideas how to do so. – NewUser Apr 25 '22 at 10:24
  • 1
    Have you checked th link I've added in comment ? You should be able to achieve what you're after: get the list of file that have changed and then conditionally run these stages. – Thomas Apr 25 '22 at 10:26
  • I am not sure if this will work but let me provide an approach. You could define a variable (azure devops variable) which you will set on a powershell script to true or false by getting the latest changed file on git. (git commands). Then depending on which file changed you will add the condition on the stage based on the variable which you will set to only trigger the particular stage. – GeralexGR Apr 27 '22 at 10:32
  • in this approach, you will have a pipeline that will trigger another pipeline – Thomas Apr 27 '22 at 11:26
  • Ok, with conditions and pipeline variables all is looking good, but then there is another question - is there a way to set condition by trigger? I mean if triggered by PR< run stage A, if manually, run Stage B, C etc. ? – NewUser Apr 28 '22 at 08:50

0 Answers0