1. Building and publishing #
One image per commit.
Continuous delivery #
build-image:
stage: build
image: docker:29.9.3-cli
services: [docker:29.9.3-dind]
variables: { DOCKER_TLS_CERTDIR: "/certs" }
script:
- echo "$CI_JOB_TOKEN" | docker login -u gitlab-ci-token --password-stdin $CI_REGISTRY
- docker build --build-arg VERSION=$CI_COMMIT_SHORT_SHA -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA .
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
review:
stage: deploy
script: ./deploy.sh review-$CI_MERGE_REQUEST_IID
environment:
name: review/$CI_COMMIT_REF_SLUG
url: https://$CI_COMMIT_REF_SLUG.recette.exemple.fr
on_stop: stop-review
auto_stop_in: 2 days
rules: [{ if: $CI_PIPELINE_SOURCE == "merge_request_event" }]
production:
stage: deploy
script: ./deploy.sh production $CI_COMMIT_SHORT_SHA
environment: { name: production, url: https://boutique.exemple.fr }
resource_group: production
rules: [{ if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH, when: manual }]- The project container registry is accessible with
CI_JOB_TOKEN: no secret to manage to push images. - Tag per commit (
$CI_COMMIT_SHORT_SHA) and never rebuild for production: promote the same image. - Without privileged mode, build with Buildah or Kaniko; the package registry hosts npm, PyPI, Maven, NuGet and Helm.
2. Environments and deployments #
Knowing what runs where.
Environments #
environmentrecords each deployment: the Operate › Environments page shows the running version and lets you redeploy a previous version in one click (rollback).- Review apps create an environment per merge request, stopped automatically (
on_stop,auto_stop_in). resource_groupprevents two simultaneous deployments to the same environment.- Protected environments and deployment approvals (Premium) restrict who can deploy to production.
Good to know : For Kubernetes, the GitLab agent (installed with Helm) opens an outbound connection to GitLab: jobs deploy with kubectl without exposing the cluster API, or the cluster pulls configuration via GitOps (Flux).Releases #
The release keyword creates a GitLab release (notes, links to artifacts) from a tag; combined with conventional commits, it automates the changelog.
Commands to know #
Commands to know
docker login registry.gitlab.com: log in to the registryglab release create v1.2.0: create a releaseglab ci run -b main --variables DEPLOY=1: pipeline with a variable
Sources #
Checked in November 2026: CI/CD platforms change every month, check versions and plans in the vendor's documentation.
