Sobes.tech
Junior — Middle

How is CI/CD process configured in GitLab?

sobes.tech AI

Answer from AI

CI/CD setup in GitLab is done using the .gitlab-ci.yml file, which is placed in the root of the repository. This file describes stages, jobs, their execution conditions, and environment.

Main steps:

  1. Defining stages: For example, build, test, deploy.

  2. Creating jobs: Each task runs in a separate container or runner. Scripts for execution are specified in the job.

  3. Configuring runners: GitLab Runner is an agent that executes tasks. You can use shared or custom runners.

  4. Execution conditions: You can specify when to run tasks (e.g., only on the main branch or when creating a merge request).

Example of a simple .gitlab-ci.yml:

stages:
  - build
  - test
  - deploy

build_job:
  stage: build
  script:
    - echo "Building the project"

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

deploy_job:
  stage: deploy
  script:
    - echo "Deploying the application"
  only:
    - main

After committing, GitLab will automatically start a pipeline that executes the described tasks in order.