In GitLab CI/CD, you can configure your pipeline jobs to run only when files in a specific directory have changed. This is done using the only
and changes
keywords in your .gitlab-ci.yml
file.
Here’s how you can set it up
The changes
keyword allows you to specify which files or directories should trigger the job. If any files in the specified path are modified, the job will run.
src/
directory changejob_name:
script:
- echo "This job runs when files in the src/ directory change."
only:
changes:
- src/*
In this example
src/
directory is modified.src/*
pattern includes all files in the src
directory.You can specify multiple files or directories by providing an array of paths under the changes
keyword.
src/
or docs/
directories changejob_name:
script:
- echo "This job runs when files in src/ or docs/ directories change."
only:
changes:
- src/*
- docs/*
This setup triggers the job when there are changes in either the src/
or docs/
directories.
You can also combine changes
with other conditions like branches
, tags
, or variables
.
main
branch and if files in src/
changejob_name:
script:
- echo "This job runs only on main branch when files in the src/ directory change."
only:
changes:
- src/*
refs:
- main
Here’s a full .gitlab-ci.yml
example that runs a job only when files in the src/
or assets/
directories change, and only on the main
branch.
stages:
- buildbuild_job:
stage: build
script:
- echo "Running build job because files in src/ or assets/ changed."
only:
changes:
- src/*
- assets/*
refs:
- main
By using the changes
keyword, you ensure your pipeline runs only when relevant changes are made, which improves efficiency.
Around the world in 80 gigs. Do you dream about flying “every night and day?” You’re not alone. A pilot was the globe’s most coveted gig w
FIRST ON FOX: A pair of Republicans are introducing legislation that would offer service members who were fired over the military’s COVID-19 vaccine mandate
London CNN — BP is planning to cut more than 5% of its 90,000-strong workforce as par
BP engineer working on drilling rig, Caspian sea, Azerbaijan. (Photo: Giles Barnard/Construction ... [+] Photography/Avalon)Getty Images Energy giant BP (LON: B