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.
Jobs are opening up in the sports industry as teams expand and money flows into the industry.Excel Search &
Fired federal workers are looking at what their futures hold. One question that's come up: Can they find similar salaries and benefits in the private sector?
After two days of increases, mortgage rates are back down again today. According to Zillow, the average 30-year fixed rate has decreased by four basis points t
Julia Coronado: I think it's too early to say that the U.S. is heading to a recession. Certainly, we have seen the U.S. just continue t