RousselTMLEARNING

DevOps

Building and delivering with GitLab: registry, environments and deployments

Delivering with GitLab CI/CD: building and publishing images to the project registry, package registry, environments and review apps, manual and protected deployments, resource_group, rollback, GitLab agent for Kubernetes and releases.

1. Building and publishing #

One image per commit.

Continuous delivery #

From commit to production
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 #

  • environment records 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_group prevents 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 registry
  • glab release create v1.2.0 : create a release
  • glab 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.

Related articles

GitLab CI/CD: concepts and architecture

Discover GitLab CI/CD: the DevSecOps platform, the .gitlab-ci.yml file, pipelines, stages and jobs, runners, …

Writing a .gitlab-ci.yml: jobs, rules, cache and artifacts

Mastering .gitlab-ci.yml syntax: stages, jobs and images, rules and workflow, needs (DAG), cache and artifact…

GitLab runners: types, executors, installation and security

Running GitLab jobs: instance, group and project runners, docker, kubernetes and docker-autoscaler executors,…

Keep learning

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!