Azure Devops - How to force a CI to be triggered on new branch, or work with Release branches?

Viewed 1883

It used to be the case that Azure DevOps would run a new CI build when you pushed a new branch to Origin. My company relied on this, as we would issue releases by creating a release/* branch off of develop which would trigger a build and a subsequent release into our testing environment. If everything passed UAT/QA, we would deploy the that same build into production.

Our Build Pipelines are both Classic UI and have two Branch filters, develop and release/*. The one product in question has two build pipelines - one for the Webjob and one for the API, and as such each pipeline has a Path filter (to, or not to, include the Webjob folder). Creating a release/* branch does not trigger either CI pipeline.

Our Release Pipeline looks like the following, where DEV is triggerd on artifacts produced from develop and TEST->PROD is triggered on artifacts built from release/* - Azure Release pipeline

This allows us to have a release environment where we iteratively make changes to get it ready, while we simultaneously make changes to develop for the next release. This is a common Gitflow model.

The Problem

Now that Azure no longer triggers a build on branch creation, I'm forced to manually run a build on Release in order to trigger the build and subsequent TEST deployment depicted in the image above.

What can I do to have automated builds and deployments in Azure while maintaining Gitflow?

3 Answers

I was also stuck not knowing why my TEST build wouldn't trigger. This post helped explain why. More searching found the way to resolve it. Simple as removing any path checks from your TEST build.

From the linked documentation:

If your pipeline has path filters, it will be triggered only if the new branch has changes to files that match that path filter. If your pipeline does not have path filters, it will be triggered even if there are no changes in the new branch.

See: Behavior of triggers when new branches are created

Not sure if you are using YAML or not but using the GUI you can add a 'path' filter for Continuous Integration and set the build to run anytime a path contains 'release'.

enter image description here

YAML pipelines are configured by default with a CI trigger on all branches.

YAML pipelines are configured by default with a CI trigger on all branches. When defining pipelines using YAML and defining a repository resource (repo for shorthand). A new pipeline run gets triggered when a commit has occurred. You can further configure the trigger to ONLY act on certain branches.

See:

Example (All branches by default):

resources:
- repo: self
  clean: true

pool:
  vmImage: 'ubuntu-20.04'
    
steps:

- task: CMake@1
  displayName: 'Generate Makefile'
  inputs:
    workingDirectory: $(Build.SourcesDirectory)
    cmakeArgs: '-B$(Agent.BuildDirectory) -H.'

- task: Bash@3
  displayName: 'Build project'
  inputs:
    workingDirectory: $(Agent.BuildDirectory)
    targetType: 'inline'
    script: 'make -j4'

Limit to release branches (add trigger to repository resource):

trigger:              # Optional; Triggers are enabled by default
      branches:       # branch conditions to filter the events, optional; Defaults to all branches.
        include:
        - release/*
Related