How to trigger pipeline for multiple project from single repo - gitlab

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

Related

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.

Gitlab CI: Using wildcard with include keyword

I am using below to trigger pipeline if any changes are made in the folders under root directory.
trigger_serviceA:
stage: triggers
rules:
- if: '$CI_COMMIT_BRANCH == "dev"'
changes:
- serviceA/*
when: always
trigger:
include: serviceA/.gitlab-ci.yml
strategy: depend
However, pipeline is not getting triggered if there are any changes in the subfolders under serviceA.
When using only:changes the single wildcard does not covers subdirs - you'll have to use /**/* instead.
Altough the documentation does not say it, i could imagine that it's the same for rules:changes - so maybe you'll want to try that out.

Trigger a pipeline when specific file is changed

I am creating a new CI pipeline that will be triggered anytime a .bicep file is changed and then zip up all of the files.
# Pipeline is triggered anytime there is a change to .bicep files
trigger:
branches:
include:
- "feature/*"
pool:
vmImage: ubuntu-latest
steps:
- script: echo Hello, world!
displayName: 'Run a one-line script'
This pipeline works and is triggered anytime a change is made in the feature branch.
To target any .bicep files I am trying:
trigger:
branches:
include:
- "feature/*"
paths:
include:
- '**/*.bicep'
I also tried to specify the entire route that holds the files:
trigger:
branches:
include:
- "feature/*"
paths:
include:
- "src/Deployment/IaC/Bicep/*"
When I make a change to a .bicep file in the feature branch, the pipeline is never triggered so I know my syntax is wrong.
Wildcards are not supported anymore for azure pipelines.
Instead just set the relative path to your Bicep folder like so :
paths:
include:
- src/Deployment/IaC/Bicep
see : https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/azure-repos-git?tabs=yaml&view=azure-devops#paths

Azure DevOps Pipeline: exclude paths for PRs

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

How to exclude one branch in Azure DevOps build pipeline

In Azure DevOps its possible to define build pipelines which by default is executed when a code is pushed to a branch.
I want the pipeline to run for all branches except one. The configuration
trigger:
branches:
include:
- branchToInclude
exclude:
- branchToExclude
works when I push to branchToInclude.
But if I take away the include part the pipeline is not executed when I push to branchToInclude.
trigger:
branches:
exclude:
- branchToExclude
A * instead of branchToInclude is not accepted when I try to save the file. Is there a way to configure a pipeline to execute for all branches except one?
I suppose something like this should work
trigger:
branches:
include:
- '*'
exclude:
- branchToExclude

Resources