Driving Job Execution, Timing, and Dependencies with Conditions and Rules
56%
Setting Job Types Based on Conditions
This section focuses on changing how a job is triggered, not just whether it runs, by selecting different job types such as manual or delayed based on pipeline conditions.
Example:
You want to run a job only when the target branch of the merge request is protected. If it's the case, you want to set the job to be triggered manually:
build_job:
stage: build
script:
- echo "running build_job"
rules:
- if: '$CI_MERGE_REQUEST_TARGET_BRANCH_PROTECTED == "true"'
when: manual
When a job is set to manual, it will not run automatically. The pipeline will stop at this job and wait for a user action. To allow the pipeline to continue, we can use the allow_failure: true clause:
build_job:
stage: build
script:
- echo "running build_job"
rules:
- if:Cloud Native CI/CD with GitLab
From Commit to Production ReadyEnroll now to unlock all content and receive all future updates for free.
