skip to Main Content

Base on this article Triggering an Azure Devops pipeline from another pipeline, I’m attempting to configure the dependent pipeline to run only when the source pipeline is triggered by a tag push. Below are the configurations for both pipelines:

source pipeline

trigger:
  branches:
    include: # branch names which will trigger a build
    - main
  tags:
    include:
    - '*'
pr: none

steps:
  # required to cause pipeline triggering downstream
  - task: CopyFiles@2
    inputs:
      contents: $(System.DefaultWorkingDirectory)/**/*.yml
      targetFolder: $(Build.ArtifactStagingDirectory)
  - task: PublishBuildArtifacts@1
    inputs:
      pathtoPublish: $(Build.ArtifactStagingDirectory)
      artifactName: dummy-$(Build.BuildId)

depends pipeline

trigger: none

pr: none

resources:
  pipelines:
    - pipeline: source
      # project: Pipelining
      source: source
      trigger: 
        branches:
          include:
          - main
        tags:
        - '*'

steps:
  - checkout: none
  - script: echo 'triggered depends'

The result is the depends pipeline not triggered.

I attempted to adjust the tag trigger configuration for the dependent pipeline, aiming to specify a particular tag instead of using a wildcard character ‘*’ as per the documentation on Azure Pipelines YAML schema https://learn.microsoft.com/en-us/azure/devops/pipelines/process/resources?view=azure-devops&tabs=schema#define-a-pipelines-resource.

However, I’m uncertain whether Azure Pipelines supports triggering a pipeline solely based on tags after another pipeline is triggered, or if tags are primarily used for filtering trigger events.

2

Answers


  1. If I’m not mistaken, wildcards such as * can be used to filter branches but not tags.

    So, instead of:

    resources:
      pipelines:
        - pipeline: source
          # project: Pipelining
          source: source
          trigger: 
            branches:
              include:
              - main
            tags:
            - '*'
    

    Try:

    resources:
      pipelines:
        - pipeline: source
          # project: Pipelining
          source: source
          trigger: 
            branches:
              include:
              - main
            tags:
            - mytag
    

    Please note that if you include more than one tag, the build will be triggered only when ALL the tags are added to the source pipeline.

    Login or Signup to reply.
  2. As far as I understand, the requirement was to trigger source pipeline with the commits in the tags of your repo and upon the completion of the source pipeline, the depends pipeline should be triggered.

    Based on your YAML definitions, I could reproduce the issue. This was because the tags under the trigger property of a pipeline resource was designed to filter source pipeline builds with specific build tags rather than the tagged code in our repo.

    source pipeline

    trigger:
      branches:
        include: # branch names which will trigger a build
        - main
      tags:
        include:
        - '*'
    pr: none
    
    steps:
      - script: |
          echo "##vso[build.addbuildtag]ABuildTagSource"
        displayName: Add a tag the build of source pipeline
    
      # It is not required to publish any artifacts to trigger depends pipeline; the depends pipieline should be triggerd upon the completion of the source pipeline
      # - task: CopyFiles@2
      #   inputs:
      #     contents: $(System.DefaultWorkingDirectory)/**/*.yml
      #     targetFolder: $(Build.ArtifactStagingDirectory)
    
      # - task: PublishBuildArtifacts@1
      #   inputs:
      #     pathtoPublish: $(Build.ArtifactStagingDirectory)
      #     artifactName: dummy-$(Build.BuildId)
    
    

    depends pipeline

    trigger: none
    
    pr: none
    
    resources:
      pipelines:
        - pipeline: source
          # project: Pipelining 
          source: source
          trigger: 
            branches:
              include:
              - main
            tags: # To filter builds that have specific build tag(s)
            - ABuildTagSource
    
    steps:
      - checkout: none
      - script: echo 'triggered depends'
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search