DecentWig
DecentWig

Reputation: 23

Can you branch a yaml pipeline and trigger it only with commits to that branch, using the code in that branch

I have a repo in Devops which has a yaml pipeline that builds a jar as an artifact. The trigger on this pipeline is set to master and the override YAML CI trigger setting is unticked in the GUI. I then branched this repo to make some changes. In the branch I changed the yaml files trigger to the new branch. I was expecting any commit to this branch to trigger the pipeline and build the jar based on the code in the branch. It doesn't trigger at all. I know I can manually trigger it to run on that branch but I thought this would work to automate it. Am I missing something fundamental with how pipelines work? Is this functionality even possible?

YAML in master

trigger:
  branches:
    include:
      - master

Using this trigger in main does trigger the build on a commit to the repo.

YAML in the branch

trigger:
  branches:
    include:
      - <nameOfBranch>

Using this trigger with the name of the branch does not trigger the yaml when a commit is made to the branch.

Upvotes: 0

Views: 2820

Answers (1)

bryanbcook
bryanbcook

Reputation: 18328

One of the nice advantages of YAML-based pipelines is that they can version with the code, so it's possible to make changes to the pipeline and have them immediately applied.

To demonstrate:

  1. Create a pipeline that is only triggered by changes in main. Commit the changes into a feature branch, eg feature/trigger. When you commit changes to this branch, by design the pipeline does not automatically queue.

    trigger:
      branches:
        include:
        - main
    
    pool:
      vmImage: ubuntu-latest
    
    steps:
    - script: exit 0
    
  2. Merge feature/trigger into main. The pipeline should automatically queue.

  3. Create a new branch, eg feature/trigger-test and modify the triggers to include your branch:

    trigger:
      branches:
        include:
        - main
        - feature/trigger-test
    

    Any commit to feature/trigger-test will automatically queue pipelines.

    Automatically queued pipelines

The exception for the above is scheduled triggers. Only the default branch setting for the pipeline controls the schedule.

Important notes:

  • Case sensitivity. feature/trigger and feature/Trigger are different branches.
  • Use the full path. trigger will not match feature/trigger
  • Wildcards are supported feature/*

Upvotes: 0

Related Questions