GitLab CI/CD is a tool built into GitLab for software development through continuous methodologies:
.gitlab-ci.yml
file: Defines the CI/CD pipelinestages:
- build
- test
- deploy
build_job:
stage: build
script:
- echo "Building the application"
test_job:
stage: test
script:
- echo "Running tests"
deploy_job:
stage: deploy
script:
- echo "Deploying the application"
job_name:
stage: stage_name
image: docker_image
script:
- command1
- command2
only:
- branch_name
tags:
- runner_tag
# For Debian/Ubuntu
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | sudo bash
sudo apt-get install gitlab-runner
# For CentOS/RHEL
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | sudo bash
sudo yum install gitlab-runner
sudo gitlab-runner register
sudo gitlab-runner list
sudo gitlab-runner start
sudo gitlab-runner stop
stages:
- build
- test
- deploy
build_job:
stage: build
script:
- echo "Building the application"
test_job:
stage: test
script:
- echo "Running tests"
deploy_job:
stage: deploy
script:
- echo "Deploying the application"
deploy_job:
stage: deploy
script:
- echo "Deploying the application"
only:
- master
when: manual
CI_COMMIT_SHA
: The commit revision for which project is builtCI_COMMIT_SHORT_SHA
: The first eight characters of CI_COMMIT_SHA
CI_COMMIT_REF_NAME
: The branch or tag name for which project is builtCI_JOB_ID
: The unique ID of the current jobvariables:
MY_VARIABLE: "my-value"
job_name:
script:
- echo $MY_VARIABLE
Set in GitLab UI: Settings > CI/CD > Variables
job_name:
script:
- make build
artifacts:
paths:
- build/
expire_in: 1 week
Go to your project's CI/CD > Jobs > Select a job > Download artifacts
cache:
paths:
- node_modules/
job_name:
script:
- npm install
- npm run build
job_name:
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- node_modules/
script:
- npm install
- npm run build
job_name:
image: python:3.9
script:
- python --version
build_image:
image: docker:latest
services:
- docker:dind
script:
- docker build -t my-image:$CI_COMMIT_SHA .
- docker push my-image:$CI_COMMIT_SHA
deploy_to_k8s:
image: bitnami/kubectl:latest
script:
- kubectl config set-cluster mycluster --server="$KUBE_URL" --insecure-skip-tls-verify=true
- kubectl config set-credentials admin --token="$KUBE_TOKEN"
- kubectl config set-context default --cluster=mycluster --user=admin
- kubectl config use-context default
- kubectl apply -f k8s/deployment.yaml
include:
- template: Auto-DevOps.gitlab-ci.yml
my-template.yml
) in your project.gitlab-ci.yml
:include:
- local: my-template.yml
Create a .gitlab-ci.yml
file to override or extend Auto DevOps:
include:
- template: Auto-DevOps.gitlab-ci.yml
stages:
- build
- test
- deploy
# Add your custom jobs here
include:
- template: Security/SAST.gitlab-ci.yml
include:
- template: Security/Container-Scanning.gitlab-ci.yml
include:
- template: Security/Dependency-Scanning.gitlab-ci.yml
.gitlab-ci.yml
file simple and readableGo to your project's CI/CD > Pipelines
Go to your project's CI/CD > Jobs > Select a job
job_name:
variables:
CI_DEBUG_TRACE: "true"
gitlab-runner
to debug locally:gitlab-runner exec docker job_name
2024 © All rights reserved - buraxta.com