Feedback

Chat Icon

Cloud Native CI/CD with GitLab

From Commit to Production Ready

GitLab CI/CD Core Concepts
36%

Jobs, Stages and Pipelines

There some main concepts in GitLab CI/CD like pipelines, stages, jobs, and runners that you should be familiar with. We have used some concepts in the previous sections, but we haven't seen the explanation of them yet. In this section, we are going to explain these concepts in detail.

To better illustrate these concepts, let's consider the following example:

stages:
  - build
  - test
  - deploy

build:
  stage: build
  script:
    - echo "Building the code..."

test:
  stage: test
  script:
    - echo "Running tests..."

deploy:
  stage: deploy
  script:
    - echo "Deploying the code..."

Above is a definition of a pipeline. A pipeline, by definition, is a set of "tasks" that are executed in a specific order. These tasks are called "jobs". Each job is defined by a set of commands that are executed in a specific and isolated environment. For example, the following is a job called build that runs in the build stage.

build:
  stage: build
  script:
    - echo "Building the code..."

The fact that the name of the job is the same as the stage can be confusing. The job can have any name:

stages:
  - build
  - test
  - deploy

the_build_job:
  stage: build
  script:
    - echo "Building the code..."

the_test_job:
  stage: test
  script:
    - echo "Running tests..."

the_deploy_job:
  stage: deploy
  script:
    - echo "Deploying the code..."

A GitLab Pipeline with 3 stages

A GitLab Pipeline with 3 stages

Also, a stage can have multiple jobs:

stages:
  - my_stage
  -

Cloud Native CI/CD with GitLab

From Commit to Production Ready

Enroll now to unlock all content and receive all future updates for free.