How to make Azure Pipelines yaml trigger branch with specific project? - azure-devops

I have this project repo on Github and the repo has many project in it.
So in my scenario its like this.
api-build-pipeline
project-1: trigger branch-1
ui-build-pipiline
project-2: trigger branch-1
So if I only have an update on project-1 the project-2 should not be triggered but I don't know how to do that if their trigger is the same branch.
I want the trigger something like this
trigger: - branch-1 ..project-1
Is that possible? I don't want them use different branches if possible.

You can configure the trigger to exclude or include paths to trigger the build only when a file from that project is changed.
trigger:
branches:
include:
- branch1
paths:
include:
- project1
exclude:
- project2
https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/azure-repos-git?view=azure-devops&tabs=yaml#paths

Related

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

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.

Push Build status to GitHub

I'd like to push the build status automatically from Azure Devops to the github repository, so that pull requests can check for a build success before they can be merged.
I realise this can be done writing some custom code and calling the github status api, but there is a checkbox for it in the edit pipeline stage. It doesn't seem to work with Github though. See this image .
Other build tools like Bamboo have an out of the box plugin for doing this.
You need to define branch policy. You can read about this on my blog. You need to selected existing pipeline here in GitHub settings:
and then when you make PR you will get this:
You need to correctly define trigger options in your yaml file. For isntance:
this will run for all non master branch (with each commit pushed to GitHub pipeline will run)
for each merge to master will trigger pipeline too
trigger:
branches:
include:
- '*'
exclude:
- master
pr:
branches:
include:
- master
paths:
include:
- gated-checkin/*
exclude:
- gated-checkin/azure-pipelines.yml

I'm having trouble triggering a build from a Git tag

I want to trigger a build when any of the following is true:
When there is a change to a particular branch (dev) and a subset of folders was modified (paths)
When a git tag that matches a pattern (RC* or Release*) is set and a subset of folders was modified (paths)
When I add a paths statement to my yaml build template only my branch trigger fires. I am unable to trigger off of a tag. When I remove the paths statement both my branch and tag filters work.
What am I missing?
This triggers on branch = dev or tag is either RC* or Release*
trigger:
branches:
include:
- dev
tags:
include:
- RC*
- Release*
This triggers on branch = dev only.
trigger:
branches:
include:
- dev
tags:
include:
- RC*
- Release*
paths:
include:
- /site/
I can reproduce your issue here. This issue has been confirmed as a bug and move to the product team . Please follow up this case and you can vote it to increase the priority. Sorry for this inconvenience.
Below is my reproduce:
When I added the paths trigger to the yaml, I committed the READ.md file and added the tag to the commit. However, it does not fire tag trigger. After I removing the paths trigger, the tag trigger will be fire normally.

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'