GitLab CI/CD 1 cheatsheet
GitLab CI/CD 1: Deploy and reuse
7 common GitLab CI/CD 1 tasks.
Deploy to an environment
Track deployments and their URL in GitLab.
deploy-prod:
stage: deploy
environment:
name: production
url: https://www.example.com
script:
- ./deploy.sh
Prevent concurrent deployments
Make deploy jobs run one at a time.
deploy-prod:
resource_group: production
Build a Docker image
Build and push to the project's registry, using the predefined CI variables.
build-image:
image: docker:27
services:
- docker:27-dind
script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY"
- docker build -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA" .
- docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA"
Share job settings
Define a hidden template job, and reuse it with extends.
.node-job:
image: node:24
before_script:
- npm ci
test-job:
extends: .node-job
script:
- npm test
Include other files
Include a template or a shared file from another project.
include:
- local: ci/deploy.yml
- template: Security/SAST.gitlab-ci.yml
Trigger a downstream pipeline
Start a pipeline in another project.
trigger-deploy:
trigger:
project: my-group/deploy-repo
branch: main
Useful predefined variables
Common variables GitLab sets for every job.
$CI_COMMIT_SHA
$CI_COMMIT_BRANCH
$CI_COMMIT_TAG
$CI_DEFAULT_BRANCH
$CI_PROJECT_DIR
$CI_PIPELINE_SOURCE