Azure DevOps Pipeline: exclude paths for PRs - azure

I'd like to only have CI builds on PRs to master and can't figure out how to specify that in the yaml.
My last try was:
pr:
branches:
include:
- master
paths:
exclude:
- docs/
- README.md
- CHANGELOG.md
- COPYING
- .circleci
- test/
- run_route_scripts/
- docker/
- .github/
drafts: false
which should work according to Azure's DevOps documentation. I let the change in azure config fully run on CI, then I committed only to CHANGELOG.md which triggered another build where it shouldn't have..
Note, I did not include a trigger section, as this repo practically never receives any commits to master unless it came from a PR, and I'm not sure what the side effects might be..
See the full yaml here: https://github.com/valhalla/valhalla/blob/nn_win_skip_ci/.azure-pipelines.yml

Related

Azure Devops build pipeline: CI triggers not working on PR merge to a branch when there is no work item is attached with the PR

I need to trigger the pipeline(CI) when any change is made (directly to the branch or by merging a PR) to my_branch, my yml trigger configuration is like this -
trigger:
batch: true
branches:
include:
- my_branch
paths:
include:
- path/of/the/directory
This works fine if a work item is attached with a PR and the PR is merged with the my_branch.
But, when there is no work item attached to a PR - CI is not triggering after merging the PR.
Am I missing anything?
I tried to reproduce the same in my environment and got the results successfully like below:
 Step 1: Created a sample repository. (No branch policies are applied at this stage) 
Step 2: Create a basic yaml build pipeline as below. 
trigger:
branches:
batch: true
include:
- main
pool:
vmImage: ubuntu-latest
steps:
- script: echo Hello, world!
displayName: 'Sample script'
Step 3: Create a new branch from the main branch. 
  
Step 4: Modify or add some code to the newly created branch and create a Pull Request to the main branch and verify build pipeline.
     
Note: As I did not set any pull request policies on the main branch, the build pipeline will get triggered only after the feature branch merged to the main branch.

How to trigger pipeline for multiple project from single repo

I have a gitlab repo which has two folders(folder-a and folder-b) in it, I want them to get triggered based on the commit on their folder. Currently I have a single gitlab.yml file which has below configuration. It triggers folder-a but not folder-b.
folder-a:
trigger:
include:
- local: folder-a/.gitlab-ci.yml
rules:
- changes: [folder-a/*]
folder-b:
trigger:
include:
- local: folder-b/.gitlab-ci.yml
rules:
- changes: [folder-b/*]
Sorry I had the issue with folder-b .gitlab-ci yml file. this works fine, now able to trigger folder based on commits to the branches

PR Build not ignoring README.md in azure pipeline

I have a azure-pipeline-pr.yaml file in this format which uses the GitHub repository.
pr:
branches:
include:
- dev2
- master
paths:
exclude:
- README.md
- /README.md
stages:
- stage: PR
condition: eq(variables['Build.Reason'], 'PullRequest')
displayName: prb
jobs:
Directory Structure
app1>
-azure-pipeline-pr.yml
- README.md
- src(folder)
The pr build is triggering correctly. I have raised a PR from featurex to dev2 branch and a pr build is generated.
I have not closed the above PR and I make a change to the README.md file which I have excluded in the paths:. The PR build is again getting triggered.
Can anyone please tell me what is the mistake here?
Normally the pipeline starts from the repository construction, but sometimes it is advisable to check all directories to avoid path errors.
branches:
include:
- dev2
- master
paths:
include:
- '*'
exclude:
- '**/README.md'
Please let me know if this could help.

How do I set up PR validations in Azure DevOps/GitHub?

We are migrating from Azure DevOps to GitHub and we have Build Validations set up where if you make a change in a specific folder, the respective CI pipeline will run when a PR is created.
I am trying to make use of the PR triggers in my YAML file, however when I open a PR it doesn't seem to work.
My pipeline is:
trigger: none
pr:
branches:
include:
- develop
- release/*
- ProductionSupport/*
paths:
include:
- cicd/pipelines/common/pre-commit-ci.yaml
- src
- cicd
pool:
vmImage: ubuntu-latest
variables:
PRE_COMMIT_HOME: $(Pipeline.Workspace)/pre-commit-cache
steps:
- bash: echo "##vso[task.setvariable variable=PY]`python -V`"
displayName: Get python version
- task: Cache#2
inputs:
key: pre-commit | .pre-commit-config.yaml | "$(PY)"
path: $(PRE_COMMIT_HOME)
- bash: |
pip install --quiet pre-commit
pre-commit run
displayName: 'Run pre-commit'
As a test to make sure my branches/paths were correct I updated the triggers section to:
trigger:
branches:
include:
- develop
- release/*
- ProductionSupport/*
paths:
include:
- cicd/pipelines/common/pre-commit-ci.yaml
- src
- cicd
Then when I made a change in one of the files in these folders, the pipeline was successfully triggered. Am I specifying my PR validation incorrectly?
Your yml definition seems correct.
Since you mentioned the CI trigger work fine and you mentioned We are migrating from Azure DevOps to GitHub.
This brings me a idea that a situation that exactly reproduces what you're experiencing and you might not expect:
PR Trigger Override
For example, if your pipeline is the same one as before(Just change the pipeline source), and you didn't delete the previous build validation(Or previous pipeline name is same as the current one), then the pr part in your github yml file will be override, only the build validation on DevOps side will work.
I suggest you investigate whether you have some build validation settings to the pipeline(If your project structure is complex, this maybe difficult to find) or you can simply create a totally new pipeline with the new YAML file.

Azure Devops build pipeline: CI triggers not working on PR merge to master when PR set to none

Need to trigger CI build job when a PR is merged to master (only when change is inside ./rel/* path) but not have CI build triggered when the Pull Request (PR) is created. So I have the trigger config as below.
trigger:
branches:
include:
- master
paths:
include:
- ./rel/*
pr: none # will disable PR builds (but not CI builds)
But it fails to trigger CI build when pr: none is added. If pr: none is removed, The Job is getting triggered for both PR and a merge to master. I would only need the job/CI build to run on a merge to master.
The paths filter in the YAML is looking at paths in your repository file structure, not the branch path. To have it only trigger on rel branch, replace the master under the include branches with ./rel/* (or the correct value).
We have a more defined pipeline that runs unit tests on PR and then only packages for release on merge into the master branch. We do this by having our trigger set to the master branch and using conditions for each stage in the multi-stage pipeline. Check those out as well.
Solved! This works now.
trigger:
branches:
include:
- master
paths:
include:
- ./rel/*
pr: none # will disable PR builds (but not CI builds)
Also you can configure / override using the classic azure devops UI from Triggers.
Ref : https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/azure-repos-git?view=azure-devops&tabs=classic#ci-triggers

Resources