Trigger Azure pipeline when new branch is created in releases/* - azure-devops

We want to adopt Trunk Based Development branching policy as explained here.
As a part of our solution we want to trigger Azure pipeline whenever a new release branch is created from master (trunk): for example releases/R.1
Our current yaml for said pipeline looks like this:
trigger:
branches:
include:
- releases/*
...
Unfortunately it doesn't trigger when branch is created. I suspect it will trigger when we make changes to release branch, but according to Trunk Based Development we plan to only merge cherry-picked bugfixes/hotfixes from master. Is there a way to trigger pipeline on branch creation?

Refer to this doc: Behavior of triggers when new branches are created
Here is the behavior when you push a new branch (that matches the branch filters) >to your repository:
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.
To trigger the pipeline when a new branch created, you need to remove the path filter and only set branch filter.
For example:
trigger:
- release/*
pool:
vmImage: ubuntu-latest
steps:
- script: echo Hello, world!
displayName: 'Run a one-line script'

Related

pull request doesn't trigger build pipeline

trigger:
branches:
include:
- master
tags:
include:
- Showcase
pr:
branches:
include:
- master
the code above is from my yaml azure pipeline with using bitbucket repo. Anytime I do a PR in my bitbucket repository I expect build pipeline to run automatically in azure devops but it's not the case. Currently, I have to run the pipeline manually to complete PR validation. creating pipeline with the same line of code under another repo works correctly. I'm not sure what the problem is.
I created anoter dummy pipeline with a new project, the pr triggered build automatically when pr to the the master. the webhohook seems to be working fine. the trigger option doesn't override the yaml pipeline. I can't think of anything else to check.

Triggers in Azure devops with many branches in repository

On a migration from gitlab to azure, we need to specify triggers. I have a pipeline on my main (azure-pipelines.yml) which describes the pipeline, I have a trigger condition
trigger:
- none
pr:
branches:
include:
- main
This is purely to make sure that after the merge to main has happened, the pipeline is triggered.
However, if I create any feature to this repo, I create a new branch ( featureX) from master and it will have the same azure-pipelines.yml file. On this branch, I would like the SW to be built for every commit I do to that branch ( featureX). So it makes sense to have the trigger in the branch ( featureX) as follows:
trigger:
branches:
include:
- '*'
Now when the merge is ready, is it a best practise to delete the pipeline file from the featureBranch or do we change the trigger in the yml file of featureBranch?
Or is it handled in a way which I did not mention here?
So you want to trigger a build for every PR and for any feature branches?
If I understand that correctly, keep a single azure-pipelines.yml file and just add a branch trigger:
trigger:
branches:
include:
- feature/*
pr:
branches:
include:
- main

DevOps YAML build pipeline multi-repo trigger branch not identified by Release Pipeline for continuous deployment trigger or artifact filter

I have a YAML build pipeline which resides on the repo PipelineRepo, branch master.
It contains a reference to a second repo AppRepo with a trigger on branch dev.
When a commit is made on AppRepo/dev, the build triggers and produces an artifact. The Build.SourceBranch predefined variable available during the build is of course dev as this was the triggering branch on AppRepo. This is as per the docs here:
https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/multi-repo-checkout?view=azure-devops#triggers
The specific part of the docs is this:
When an update to one of the repositories triggers a pipeline, then
the following variables are set based on triggering repository:
Build.Repository.ID
Build.Repository.Name
Build.Repository.Provider
Build.Repository.Uri
Build.SourceBranch
Build.SourceBranchName
Build.SourceVersion
Build.SourceVersionMessage
I consume the artifact in a Release pipeline, where I have a "Dev" stage with an artifact filter for branch dev:
I have a continuous deployment trigger on the artifact for branch dev:
Now we come to the problem
Every time a new build artifact is produced from the AppRepo/dev branch, the continuous deployment trigger doesn't fire because it thinks the build branch of the artifact was PipelineRepo/master. This is also true of the artifact filter on the stage - I have tested it by changing the continuous deployment trigger to master.
Note: you can see on the screenshot the build name contains the word "dev". This is because I use the Build.SourceBranch var in my custom build name. This proves the artifact is definitely produced by the AppRepo/dev triggering branch.
How can I get the DevOps Release Pipeline to pick up the triggering branch?
Based on your description, I could reproduce the similar issue in my organization.
When the pipeline is triggered by another repo branch, it still show the master branch in Release artifacts.
At the same time, the display of the trigger branch is also inconsistent in Pipelines.
For example:
Overview:
Detail view:
I suggest that you could create a feedback ticket in Our feedback Site.
For a workaround:
You could add a build tag in Pipeline to distinguish artifacts.
Yaml sample:
resources:
repositories:
- repository: test
type: git
name: 123/ARM
trigger:
- test
steps:
- checkout: test
- script: echo "##vso[build.addbuildtag]$(Build.SourceBranch)"
Release Pipeline:
You could set the master branch and add the build tag.

How do I set up different pipelines for each branch in Azure

I have a single project but with two "master" branches.
master
virt/master
Each of them would have their own azure-pipeline.yml specific for their branch.
The first pipeline in master has the trigger set up as
trigger:
batch: true
branches:
include:
- refs/heads/master
The second one is in the virt/master branch.
trigger:
batch: true
branches:
include:
- refs/heads/virt/master
Here's the repository that I am experimenting on https://dev.azure.com/trajano/experiments/_git/multi-branch
master build https://dev.azure.com/trajano/experiments/_build?definitionId=11
virt/master build https://dev.azure.com/trajano/experiments/_build?definitionId=12
The problem I am having is when I push a change to the virt/master branch both pipelines get executed
Am I missing something in my configuration? Or is this a bug on Azure Devops?
I also tried to exclude but to no avail.
trigger:
batch: true
branches:
include:
- refs/heads/master
exclude:
- refs/heads/virt/master
If you want to have separate pipelines please create separate file definition for them. I think that your configuration is fine and the issue is that you share the same file as definition.
When I moved to separate file it works as expected:
To create different pipelines for different branches. You need to rename the azure-pipelines.yml file in virt/master branch or create a new yml file with the some contents and with a different name. And create pipeline multi-branch(virt) from this new yml file.
If both pipelines are created from the yaml file with the same name azure-pipeline.yml. And the azure-pipeline.yml file exists in both of the branches. Then they are identical pipelines(even though the azure-pipeline.yml file contents might be different).
You can see from above screen. Pipeline multi-branch and multi-branch(virt) were building the same virt/master branch(using the tasks in the azure-pipeline.yml of virt/master). If you push to master branch. You will see both pipelines will be triggered to build master branch(using the tasks in the azure-pipeline.yml of master). Pipeline multi-branch and multi-branch(virt) are one pipeline
See this thread for more information.

Azure DevOps run build on branch creation

My pipeline looks like:
trigger:
branches:
include:
- release-*
jobs:
- job: release
condition: contains(variables['Build.SourceBranch'], 'refs/heads/release-')
pool:
vmImage: 'windows-latest'
steps:
- bash: |
echo "RELEASE"
displayName: 'release_task1'
How can I make it executed automatically when new release-.. branch is created?
How can I make it executed automatically when new release-.. branch is created?
This is a limitation of YAML trigger.
If the yaml file is not present in the new create branch, the build will not be triggered.
That is reason why it does not execute automatically when creating a new release ... branch.
To resolve this issue, we need to create the yaml file in the basic branch, like release-basic, then we create a new branch based on the branch release-basic. Now the build will be executed automatically.
Hope this helps.