Trigger specific build pipeline in Azure Dev Ops with single repository(.sln) having multiple projects(.csproj) - azure-devops

I've a single repository having visual studio solution(.sln), where I've more than one project(.csproj) in same solution(i.e. WebAPI project, WebApp project etc.)...
Now, I've created separate pipeline(s) for individual project, which trigger whenever any commit comes to my XYZ branch...(ex. through PR code merge from feature to XYZ branch)
Now, the issue is...
Whenever any commit come to any project in that repository all pipeline start building there respective projects... Here I just want to build a specific project pipeline for which the commit file(s) comes into...

You can specify file paths to include or exclude.
# specific path build
trigger:
branches:
include:
- master
- releases/*
paths:
include:
- docs
exclude:
- docs/README.md
When you specify paths, you must explicitly specify branches to trigger on. You can't trigger a pipeline with only a path filter; you must also have a branch filter, and the changed files that match the path filter must be from a branch that matches the branch filter.
Check here:
https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/azure-repos-git?view=azure-devops&tabs=yaml#ci-triggers

Related

Skip pipeline build on branch creation

My YAML file does not have any triggers configured, so it runs on every commit, which I am happy with. But it also runs every time I create a new branch. As this code is identical to that which it was branched from, there is no point to this, and it is rolling my build numbers, without any new work actually being done. Is there a way to skip the build pipeline on branch creation?
According to the official documentation:
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.
So, I would try to include some path filters to your trigger, but the way they cover all files. It could be something like this:
trigger:
paths:
include:
- */*
Or, in case the above include filter doesn't work, you can try to build an exclude filter, which will also mean "all files included", like:
trigger:
paths:
exclude:
- non_existing_folder/*
I don't have the Azure DevOps env at my expose to try this out right now, but hope you get the idea.

how to trigger pipeline from only feature/topic branch in azure devops?

I'm trying to develop a pipeline from feature-branch.
sample-code:
trigger:
branches:
include:
- deploy-pipeline/sql/test/*
exclude:
- deploy-pipeline/pipeline/*
- deploy-pipeline/sql/sample_scripts/*
Here deploy-pipeline is the name of the feature branch. I have azure-pipeline.yml file in the feature branch. I want to deploy only sql scripts inside deploy-pipeline/sql/test/ so i have included it in the include flag, whenever there's any change in sql/test folder the pipeline should trigger automatically and deploy sql scripts to my test environment. Once I tested this functionality working as expected then I can push this pipeline structure to master to deploy sql scripts only in specific folder.
I tested pushing changes to the sql/test folder, sample sql scripts. But the pipeline isn't triggering automatically. Not sure where I'm missing it. Please help me.
In trigger branches, what you need to write is the name of your branch. If your branch name is deploy-pipeline/sql/test, you don't need to write /* behind it to indicate every files in the branch.
In the other words, you just need to write the branch name in trigger, then every thing in the branch can trigger the pipeline.
So the script should be like this:
trigger:
branches:
include:
- deploy-pipeline/sql/test
exclude:
- deploy-pipeline/pipeline
- deploy-pipeline/sql/sample_scripts
I guess you might be confusing path triggers with branch triggers. Only branch names can be written in the branch trigger and only path can be written in the path trigger.
Click CI triggers for detailed information and examples.

Trigger Build in Azure DevOps based on Subfolder commit

I have four folders in my Azure DevOps repo. I'm looking if I commit any change in folder A only that folder should trigger.
Is there any way to achieve this with single build definition.
You can add a path filter in your trigger. For example:
trigger:
branches:
include:
- main
paths:
include:
- A/*
This pipeline will be triggered only if you commit changes in folder A. Here is the document about Path filters in CI trigger and you can find more detailed information there.

Paths to specific project in trigger not working when triggered from a branch

We currently use Azure DevOps for our builds and have set up triggers for branches. We have a solution that contains multiple projects. To build a spefic project, we have included "paths" to include the project in the build.
However, when a build is triggered from a branch that is not the master branch, all projects are built. When triggering directly from the master branch, only the specific project is built (as expected).
Is there a way to set the "Paths: Include:" to build just the specific project for all branches?
YAML code for the trigger:
trigger:
branches:
include:
- master
- bugfix/*
- task/*
- feature/*
paths:
include:
- '/Project1'

Build trigger is not invoked on push for Azure Git repositories

I have my git repository hosted on Azure DevOps. I created a new yaml based build pipeline in the master branch and have set the trigger section to two existing branches. Other branches don't have a azure-pipeline.yml file nor any kind of branch policies are set for this DevOps project.
trigger:
batch: 'true'
branches:
include:
- master
- develop
The trigger gets invoked for every change in the master branch as expected. But is ignoring any pushes to the develop branch.
If I configure a build pipeline with the visual editor and define the exact two branches there, for every push a build will be triggered.
Any idea how Azure Pipeline respects the build definition also for other branches without copy and pasting the whole definition for every possible branch?
Build trigger is not invoked on push for Azure Git repositories
I have created a sample with the syntax:
trigger:
batch: 'true'
branches:
include:
- master
- Dev
And it works fine on my side. Then I check the new project you provided, but I found that the .yml file is incomplete and does not contain a trigger: node.
So, to resolve this issue, we need to double check the .yml file you modified in under the master branch, and you build .yml file is you modified.
Besides, when we edit the build pipeline, there is a extended button, we could select the option Triggers to set the build trigger with visual editor:
If above not help you, you can try to create a new build pipeline, set the trigger only with Develop branch, check if it works fine, then return to the previous with master
and develop branch.
If all of the above methods are not worked, you may need share a detailed sample and some steps, the reason for this problem may be hidden in the corner we ignore.
Hope this helps.