CI/CD

CI/CD

It is important to distinguish between the Git tool and software forges built on Git, such as GitHub, GitLab, or BitBucket. The forge allows you to create and centralize an organization’s Git repositories. It offers repository users features such as code review, continuous integration, vulnerability scanning, and container or package registry.

git and forges

GitLab CI/CD

GitLab CI/CD is GitLab’s built-in automation tool. It enables developers to implement the entire CI/CD process directly within their GitLab repositories.

To define the CI/CD pipeline, we write a .gitlab-ci.yml file at the root of the project. Inside, we express what happens at each stage. For example:

 1build:
 2  stage: build
 3  script:
 4    - echo "Building the application"
 5test:
 6  stage: test
 7  script:
 8    - echo "Testing the application"
 9deploy:
10  stage: deploy
11  script:
12    - echo "Deploying the application"

As soon as the file is committed to the repository, the pipeline is triggered and executes the tasks described. You can track the progress of pipelines from the Build > Pipelines menu.

simple pipeline 01

Clicking on the progress status displays a view of the pipeline and allows you to track its progress in (almost) real time.

simple pipeline 02

Clicking on a job displays its logs.

simple pipeline 03

Gradle-based Java project

For a Gradle-based Java project, you can add a continuous integration step like this:

 1include:
 2  - component: gitlab.com/components/sast/sast@main
 3
 4test:
 5  stage: test
 6  image: eclipse-temurin:21-jdk-alpine
 7  before_script:
 8    - cd backend
 9  script:
10    - ./gradlew test
Note
GitLab schedules the job on a GitLab Runner, a worker process. A runner uses an executor to run the job. If an image is specified in the job definition in .gitlab-ci.yml, then the runner relies on an executor capable of creating Docker containers. It is in this container that the job finds the tools it needs, in this case javac and java.