GitLab CI/CD Pipelines

GitLab CI/CD, which stands for Continuous Integration and Continuous Deployment, is about automating the software delivery process. By automating steps like building, testing and deploying, it is ensured that developers can release software more rapidly and with higher quality.

Continuous Integration

The Continuous Integration concept resolves around the practice of integrating code changes frequently, sometimes even several times a day. This means that as developers submit their changes, these will be automatically tested to ensure they meet quality standards and are compatible with the existing codebase.

Continuous Deployment

The Continuous Deployment or Delivery part deals with getting the integrated and tested code out to the user. Once the code passes all its tests, it can be automatically deployed to production, stating, or any other predefined environment.

Create a Simple Pipeline

All these processes or jobs are defined in a file called .gitlab-ci.yml, which is stored within the code repository. To run the these jobs, a so called Runner is required. These are essentially agents that pick up the job and execute them. These runners can be hosted on various platforms, supporting configurations ranging from Docker to Kubernetes.

build-job:  
  script:  
    - echo "Hello World!"

In the example above you see a basic pipeline example. The jobs is called build-job and when executed it will print out Hello World. This will happen every time someone commits to the repository. To create the pipeline, create a new file called .gitlab-ci.yml and place it in the root directory of your repository.

To view the execution, navigate to the GitLab UI and select on the sidebar Build > Jobs and click on the job number.

GitLab CI/CD Pipeline Execution

Run Jobs in Sequence

Each job in a GitLab pipeline belongs to a single stage. A stage can contain zero, one or more jobs. All jobs in a single stage run in parallel. The next stage is executed only if all jobs from previous stage complete successfully. Out of the box GitLab has defined the following three stages:

stages:  
    - build  
    - test  
    - deploy

The stages run in sequences, so if build complete with success, GitLab proceeds with test, starting all jobs from that stage in parallel.

stages:  
- build  
- test  
- deploy  

build:  
stage: build  
script:  
- echo "This job builds something."  

test:  
stage: test  
script:  
- echo "This job tests something else. It will only run when all jobs in the"  
- echo "build stage are complete too. It will start at about the same time as test_a."  

deploy:  
stage: deploy  
script:  
- echo "This job deploys something. It will only run when all jobs in the"  
- echo "test stage complete."  
environment: production

If you update your .gitlab-ci.yml file in inside the repository with the code above and navigate again to the pipeline section, you will see this time three jobs which are running in sequence.

GitLab CI/CD Pipeline with Stages

This should help you to get starting with your own CI/CD pipelines in GitLab. It is a fundamental concept of modern software development.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top