RousselTMLEARNING

Article · GitLab CI/CD: from discovery to expertise

Reusing and securing

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.

📄 Reusing and securing GitLab pipelines →

My progress

  • ⏱ Estimated time : ≈ 6 min

Sign in to track your progress and take notes. Sign in

⭐ Rate this lesson

5.0 initial rating from the teaching team

Sign in to rate this lesson →

💬 Questions about this lesson

No questions yet: be the first to ask for help or share your configuration.

Ask a question about this lesson →

Recommended Articles

Reusing and securing GitHub Actions workflows

Industrializing GitHub Actions: reusable workflows, composite, JavaScript and Docker actions, lea...

DevSecOps: securing the software supply chain end to end

Integrate security into the DevOps pipeline: shift-left, threat modeling, secret detection, SAST,...

GitLab CI/CD best practices and troubleshooting

Running GitLab CI/CD day to day: speeding up pipelines, controlling compute minutes, organizing f...

Terraform in CI/CD: pipelines, plan review, OIDC and GitOps

Automate Terraform: plan pipeline on merge requests and apply after approval, posting the plan as...

GitLab runners: types, executors, installation and security

Running GitLab jobs: instance, group and project runners, docker, kubernetes and docker-autoscale...

GitLab CI/CD: concepts and architecture

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

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 ...

Building and delivering with GitLab: registry, environments and deployments

Delivering with GitLab CI/CD: building and publishing images to the project registry, package reg...

Azure YAML pipelines: stages, tasks, variables and templates

Writing Azure pipelines in YAML: trigger and pr triggers, stages, jobs and steps, versioned tasks...

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!