GitLab CI/CD Core Concepts
Stageless Pipelines: The "needs" Keyword
In the common way of defining pipelines, jobs are grouped into stages. If you're starting with CI/CD in general, you will likely get an idea about CI/CD being a process of building, testing, and deploying code. Therefore, you might be tempted to define stages like build, test, and deploy in your pipeline. However, when you work on complex projects, involving multiple services, teams, developers and environments, you might find that the traditional stage-based approach is not flexible enough to meet your needs.
Traditionally, GitLab pipelines were also divided into stages, and jobs were executed sequentially by stage and they still are. However, in GitLab 14.2, a major improvement to pipeline flexibility was introduced: the ability to create "stageless" pipelines.
With the new approach, you can fully control the execution order using only the needs keyword, allowing jobs to run based on their dependencies rather than being constrained by stage order. This not only simplifies pipeline configuration but can significantly speed up execution times.
We'll dive deeper into this flexible, stageless pipeline approach later in the guide but at this point, it's important to remember that the following pipeline, defining no stages, is perfectly valid:
job1:
script:
- echo "Job 1 - No dependencies"
job2:
script:
- echo "Job 2 - Depends on Job 1"
needs:
- job1
job3:
script:
- echo "Job 3 - Depends on Job 2"
needs:
-Cloud Native CI/CD with GitLab
From Commit to Production ReadyEnroll now to unlock all content and receive all future updates for free.
