Gitlab CI run job when files changed only
- User
Gitlab CI run job when files changed only
- Assistant
To run a job in GitLab CI only when specific files have changed, you can use the
onlykeyword in your job configuration.For example, you can specify that a job should only run when a specific file has changed by referencing the file path. Here's an example of a job configuration that runs only when a file named
script.shhas changed:my_job: script: - echo "Running my job" only: changes: - script.shIn this configuration, the
my_jobjob will only run when thescript.shfile has changed.You can also specify multiple files or file paths for the job to run when any of them have changed:
my_job: script: - echo "Running my job" only: changes: - file1.txt - file2/*.mdIn this configuration, the
my_jobjob will run when eitherfile1.txtor any Markdown file in thefile2directory has changed.Additionally, you can also use regular expressions to match file paths for the job to run: