Trigger Azure DevOps CI using continuous integration - azure

I need assistance on how to trigger a particular CI when we have multiple projects in one branch.
In my case - I have one project, in the project I have one repository, inside the repository I have one branch, inside the branch I have multiple projects (.CSPROJ) and one solution file(.SLN). If there is a change in project A my CI should get trigger only for that particular project. The other CI which is referring to Project B should not get trigger which is in the same branch.
Pleas assist on this request.

Please check the trigger official document:
https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/azure-repos-git?view=azure-devops&tabs=yaml#paths
Such as:
trigger:
paths:
include:
- some/path/1/*
and
trigger:
paths:
include:
- some/path/2/*

Related

MultiStage Pipeline triggers from more than one branch

I have a pipeline in Azure DevOps that is triggering from more than just the branch I have specified in the yaml file. I am using bitbucket cloud for my repository.
At first I had the trigger set like this:
trigger:
- development
Then I changed it to this:
trigger:
branches:
include:
- development
It is still triggering from 2 other branches besides development. When I look at the branches tab on the pipeline it has development and the other 2 branches it's triggering from. I also don't have any triggers set in the UI.
Any ideas? Thanks.
Have you updated the YAML file in the correct branch? The branch the pipeline definition is derived from?
As a workaround you could try to add the excludes clause in your YAML trigger to ignore those other two branches.
trigger:
branches:
include:
- development
exclude:
- PBI123
- PBI456
A note on the Branches tab, this is a summary of the pipeline runs that have already been executed, it is not a listing of the branches what will be executed by the pipeline.
I hope this helps resolve your issue.
Ok after looking into it some more I believe this solves it:
pr: none
As long as the PR has that in it. It shouldn't trigger.

GitHub PR Merge does not trigger Azure DevOps Pipeline

I have my repository on GitHub and my CI/CD pipelines on Azure DevOps. What I want to achieve is, that once a PR merges onto the master branch that the pipeline deploys. No PR creation should trigger the pipeline. Unfortunately I can't seem to get the trigger right.
My trigger looks like this:
trigger:
branches:
include:
- master
pr: none
When I push changes onto the master branch, the pipeline gets triggered. But if I do it via GitHub PR, nothing happens. I also tried it with release pipelines but I seem to have the same problem there. Any pointers in the right direction would be much appreciated!
I'd suggest just use trigger for CI
trigger:
branches:
include:
- master
Omit the pr section.
This would then run your pipeline whenever you make a PR to master as well as once you complete the PR.
And now to prevent the pipeline from running whenever you make the PR and only once you complete the PR to master, use a condition on your build stage
- stage: 'Build'
displayName: 'Build my application'
condition: eq(variables['Build.SourceBranchName'], 'master')
jobs:
etc.....
I have figured it out. Something is completely off in my repository. No idea how I managed that, since I thought that should not even be possible.
Anyway, I tried the triggers with an empty repository and it works like a charm.
I had a similar thing with Pull-Requests from Github. In the end i just used the old school "triggers" section and it started working.
Just edit the pipeline and in the "..." drop down selected triggers and then go to the "Pull Request Validation" row and enable it. Lastly pick the target branch.
Note: sometimes is can take a few minutes for DevOps to pick it up.

Azure DevOps Pipeline - wildcard not trigger pipeline

I would like to ask you what is a the reason of not running a pipeline after making a commit from Visual Studio to repository located in Azure DevOps? Has trigger in yaml lower priority from trigger builded inside pipeline where default is set to develop (Yaml -GetSource)?
My current yaml code:
trigger:
branches:
include:
- feature/*
Name of my current branch local/origin:
feature/employer-service
Thanks in advance for all answers.
As you found in the comment, if you want the branch to get CI triggers, you need to make sure that the same azure-pipelines.yml file exists on the branch.
You can switch to each branch on the pipeline page to check whether the azure-pipelines.yml file is included. If it does not exist, you will get the following error.
Thank you for your time, I've found solution:
In order to run pipeline after making commit from repository, you have to add separate yaml file to branch which actually you are pushing.
I had yaml file on develop branch but the necessary was to add a similar yaml file with whole setup to a new branch.

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

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/* -
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?
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'.
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:
CI triggers - MSDN
Repo triggers
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/*

What is the purpose of `Build branch filters` in Continuous deployment trigger?

A build pipeline can be tied to only 1 source branch.
In release pipeline, we configure an artifact by selecting the source build pipeline. So a release artifact can be tied to only 1 build pipeline.
What is the purpose of Build branch filters in Continuous deployment trigger?
Let say that your code base was updated. You want deploy only if build was made over specific branch (example develop).
In that scenario Build Branch Filter looks fairly redundant... but what if:
You want to trigger new deployment for every latest artifact, built from each feature branch to get them tested. You have to filter for feature/*.
You want to trigger new deployments if your release branches are updated, but some of them are deprecated and you need to filter them out. I that scenario specify one include filter release/* and second exclude filter release/old*.
Anyway.. in most of the cases the filter and the branch name (in artifact) will match each other. Still sometimes it can be heady to trigger deployment from multiple branches or filter something out.
In regards to your comment, I uploaded part of the yaml build. In fact one build can create artifacts from all branches in repository if you want.
trigger:
branches:
include:
- feature/*
- bugfix/*
- release/*
- develop
- master
exclude:
- experimental/*

Resources