Conditional Jobs and Pipelines
63%
Using Conditions Based on Files
Sometimes you want to run a job only when a file exists or has been modified. In this case, you can use the exists and changes keywords. Let's see some examples.
Example:
You want to run a job only when the file ok exists:
build_job:
stage: build
script:
- echo "running build_job"
rules:
- exists:
- ok
Example:
You want to run a job only when the file requirements.txt has been modified:
build_job:
stage: build
script:
- echo "running build_job"
rules:
- changes:
- requirements.txt
Example:
You want to run a job only when the file requirements.txt has been modified and ok exists:
build_job:
stage: build
script:
- echo "running build_job"
rules:
- changes:
- requirements.txt
- exists:
- ok
Example:
You want to run a job only when the file requirements.txt or Dockerfile has been modified:
build_job:
stage: build
script:
- echo "running build_job"
rules:
- changes:
- requirements.txt
- Dockerfile
Cloud Native CI/CD with GitLab
From Commit to Production ReadyEnroll now to unlock all content and receive all future updates for free.
