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.
FLORIDA- Spirit Airlines (NK) has officially retires the last Airbus A319 from its fleet, marking the end of an era for the budget carrier. The fin
SEGUIN, Texas – Are you in the Hill Country area and looking for a job?A collaborative effort between Seguin, New Braunfels, Cibolo and Schertz’s economic p
Want to stay current with Arthur’s writing? Sign up to get an email every time a new column comes out.“My job is a Kafkaesque nightmare,” a young friend t
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