Pipelines serve as the top-level component of CI/CD in GitLab. They consist of two primary elements:
build-job:
stage: build
script:
- echo "Hello, $GITLAB_USER_LOGIN!"
test-job1:
stage: test
script:
- echo "This job tests something"
test-job2:
stage: test
script:
- echo "This job tests something, but takes more time than test-job1."
- echo "After the echo commands complete, it runs the sleep command for 20 seconds"
- echo "which simulates a test that runs 20 seconds longer than test-job1"
- sleep 20
deploy-prod:
stage: deploy
script:
- echo "This job deploys something from the $CI_COMMIT_BRANCH branch."
environment: production
Jobs
Jobs are executed by GitLab runners.
Multiple jobs in the same stage are executed in parallel (depending on the concurrent runners).
If all jobs in any particular stage succeed, the pipeline will move ahead to the next stage.
If any job in any particular stage fails, the next stage will not be executed and the pipeline will be stopped at that same point.
Stages
Stages, define when to run the jobs and how to run the jobs.
We can have different stages for different sections like building, testing, and deploying.
A stage can have zero, one, or multiple jobs inside to execute.
All jobs in a particular stage run in parallel.
The next stage in a pipeline will be executed only if all jobs from the previous stage are completed successfully.
Default Stages
In GitLab, the Default pipeline stages are: