azure-devopsazure-pipelinesazure-pipelines-yaml

Trigger on pipeline and with path filter


I would like to trigger a pipeline when a stage in another pipeline has completed, but I only want to do it if there have been changes in a specific folder.

Triggering based on the source pipeline works as expected, but I don't see an option for setting path filters. If I add a normal trigger on path, it gets executed immediately if there are changes in the folder, and not when the source pipeline has completed:

trigger:
  paths:
    include:
    - path/to/folder/*

resources:
  pipelines:
  - pipeline: SourcePipeline
    source: SourcePipeline
    trigger:
      stages:
        - sourcestage

Is this possible to achieve in ADO? I guess an alternative is to still trigger it, but make a step or condition in the pipeline that aborts if no changes to files in the folder.


Solution

  • Path filters are not supported in the pipeline resource.

    If you are able to detect if the folder changes in the source build, consider adding a build tag when that happens - for example, HAS_CHANGES:

    - task: Bash@3
        inputs:
        targetType: 'inline'
        script: |
          echo "##vso[build.addbuildtag]$HAS_CHANGES"
        displayName: 'Set build tag: HAS_CHANGES'
    

    You can then configure the pipeline resource in the destination pipeline as follows:

    resources:
      pipelines:
      - pipeline: SourcePipeline
        source: SourcePipeline
        trigger:
          tags: # List of tags that when matched will trigger the pipeline. 
            - HAS_CHANGES
          stages: # List of stages that when complete will trigger the pipeline. 
            - sourcestage