Workflows: Controlling Pipelines Execution
64%
Understanding and Using Workflows
We have seen how to control the execution of a job based on conditions. For example, a job will launch only when a specific branch is pushed or when a specific user triggers the pipeline. However, sometimes you need to control the execution of the whole pipeline conditionally. We already have the tools that allows us to do that, for example, using the rules keyword in each job. But this approach becomes tedious and redundant. This is where the workflow keyword is useful.
Example:
Let's use this command to create a .gitlab-ci.yml file with a workflow that runs only when the branch name starts with feature/:
Instead of writing the following .gitlab-ci.yml file:
stages:
- build
- test
- deploy
job-1:
stage: build
script:
- echo "running job-1"
rules:
- if: '$CI_COMMIT_BRANCH =~ /^feature\//'
job-2:
stage: test
script:
- echo "running job-2"
rules:
- if: '$CI_COMMIT_BRANCH =~ /^feature\//'
job-3:
stage: deploy
script:
- echo "running job-3"
rules:
- if: '$CI_COMMIT_BRANCH =~ /^feature\//'
Cloud Native CI/CD with GitLab
From Commit to Production ReadyEnroll now to unlock all content and receive all future updates for free.
