RousselTMLEARNING

DevOps

Reusing and securing GitLab pipelines

Industrializing GitLab CI/CD: extends, anchors and !reference, include, CI/CD components and catalog, parent-child and multi-project pipelines, protected and masked variables, OIDC tokens (id_tokens) to Vault or the cloud, SAST, secret and dependency scanning, merge request pipelines and merge trains.

1. Reusing #

No more copy-paste.

The levels #

Reuse levels
# templates/python-test/template.yml (CI/CD component)
spec:
  inputs:
    python_version:
      default: "3.12"
    stage:
      default: test
---
python-test:
  stage: $[[ inputs.stage ]]
  image: python:$[[ inputs.python_version ]]-slim
  script: [pip install -r requirements-dev.txt, pytest]

# .gitlab-ci.yml of a consuming project
include:
  - component: $CI_SERVER_FQDN/mon-groupe/ci-components/python-test@1.2.0
    inputs: { python_version: "3.13" }
  - template: Jobs/SAST.gitlab-ci.yml
  - template: Jobs/Secret-Detection.gitlab-ci.yml
  • extends inherits from a hidden job (.python); !reference reuses a precise part (a script list).
  • CI/CD components are versioned (semantic tags), parameterized by spec:inputs and published to the CI/CD catalog; pin a precise version.
  • Parent-child pipelines (trigger: include) split a monorepo; multi-project pipelines (trigger: project) chain several repositories.

2. Secrets and identities #

No long-lived key in CI.

OIDC #

deploy:
  id_tokens:
    CLOUD_TOKEN:
      aud: https://iam.example-cloud.com
  script:
    - ./exchange-token.sh "$CLOUD_TOKEN"   # the provider checks project, branch and environment

id_tokens generates an OIDC token signed by GitLab for this job; AWS, Azure, Google Cloud or Vault exchange it for temporary rights, limited to a project, branch or environment. The old CI_JOB_JWT is removed.

Watch out : A masked variable is not a vault: a job can write it to a file or encode it. Restrict sensitive variables to protected branches.

3. Built-in security and merge requests #

Controls in the right place.

Scans #

TemplateDetectsPlan
Jobs/SASTcode vulnerabilitiesFree
Jobs/Secret-Detectioncommitted secretsFree
Jobs/Dependency-Scanningvulnerable dependenciesUltimate
Jobs/Container-Scanningimage vulnerabilitiesFree (rapport) / Ultimate (tableaux)
  • Merge request pipelines test the branch; merged results pipelines test the result of merging with the target.
  • Merge trains (Premium) queue merges, testing each on top of the previous ones: the main branch stays green.

Commands to know #

Commands to know
  • glab ci lint : validate includes and components
  • glab variable set NOM --masked --protected : create a protected variable
  • glab mr create --fill : open a merge request

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!