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:
-
Defining stages: For example,
build,test,deploy. -
Creating jobs: Each task runs in a separate container or runner. Scripts for execution are specified in the job.
-
Configuring runners: GitLab Runner is an agent that executes tasks. You can use shared or custom runners.
-
Execution conditions: You can specify when to run tasks (e.g., only on the
mainbranch 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.