
Votre pipeline a 50 jobs et devient ingérable ? Les pipelines parent-enfant permettent de découper un pipeline complexe en sous-pipelines indépendants. Le parent orchestre, les enfants exécutent.
Ce guide est fait pour vous si…
Section intitulée « Ce guide est fait pour vous si… »Prérequis
Section intitulée « Prérequis »Avant de continuer, assurez-vous de maîtriser :
Pourquoi des pipelines parent-enfant ?
Section intitulée « Pourquoi des pipelines parent-enfant ? »| Sans parent-enfant | Avec parent-enfant |
|---|---|
Un seul .gitlab-ci.yml géant | Fichiers séparés par composant |
| Difficile à maintenir | Responsabilité claire |
| Tout s’exécute toujours | Exécution conditionnelle par composant |
| Un échec bloque tout | Isolation des problèmes |

Configuration de base
Section intitulée « Configuration de base »Pipeline parent
Section intitulée « Pipeline parent »# .gitlab-ci.yml (racine du projet)
stages: - triggers
trigger_frontend: stage: triggers trigger: include: frontend/.gitlab-ci.yml strategy: depend
trigger_backend: stage: triggers trigger: include: backend/.gitlab-ci.yml strategy: dependPipeline enfant
Section intitulée « Pipeline enfant »stages: - build - test
build: stage: build script: - npm ci - npm run build
test: stage: test script: - npm testOptions de trigger
Section intitulée « Options de trigger »include : fichier local
Section intitulée « include : fichier local »trigger_job: trigger: include: path/to/child.ymlstrategy: depend
Section intitulée « strategy: depend »Par défaut, le parent n’attend pas la fin de l’enfant. Avec strategy: depend :
- Le parent attend la fin de l’enfant
- Le statut du parent dépend du statut de l’enfant
trigger_job: trigger: include: child.yml strategy: depend # ✅ Attend la finstrategy: depend vs strategy: mirror
Section intitulée « strategy: depend vs strategy: mirror »| Strategy | Comportement |
|---|---|
depend | Le parent attend l’enfant et hérite du statut |
mirror | Le job trigger miroire le statut du downstream (utile avec auto-cancel) |
trigger_job: trigger: include: child.yml strategy: mirror # Miroir strict du statut enfantforward : transmettre les variables
Section intitulée « forward : transmettre les variables »trigger_job: trigger: include: child.yml forward: yaml_variables: true # Variables définies dans le YAML pipeline_variables: true # Variables passées au pipeline (web, API)Passer des variables à l’enfant
Section intitulée « Passer des variables à l’enfant »Variables explicites
Section intitulée « Variables explicites »trigger_frontend: variables: ENVIRONMENT: "staging" VERSION: $CI_COMMIT_SHA trigger: include: frontend/.gitlab-ci.yml strategy: dependL’enfant peut utiliser $ENVIRONMENT et $VERSION.
Variables depuis un fichier dotenv
Section intitulée « Variables depuis un fichier dotenv »prepare: stage: prepare script: - echo "VERSION=1.2.3" >> build.env artifacts: reports: dotenv: build.env
trigger_deploy: stage: deploy needs: ["prepare"] variables: VERSION: $VERSION # Provient de build.env trigger: include: deploy.yml strategy: dependPasser des artefacts à l’enfant
Section intitulée « Passer des artefacts à l’enfant »Pour récupérer des artefacts d’un pipeline amont, GitLab fournit des mécanismes dédiés.
Parent → Child (même projet) : needs:pipeline:job
Section intitulée « Parent → Child (même projet) : needs:pipeline:job »Parent : produire un artefact + passer l’ID du pipeline au child.
build_artifacts: stage: build script: - echo "artifact from parent" > artifact.txt artifacts: paths: - artifact.txt
trigger_child: stage: deploy trigger: include: path/to/child-pipeline.yml strategy: depend variables: PARENT_PIPELINE_ID: $CI_PIPELINE_IDChild : récupérer l’artefact depuis le pipeline amont.
test_child: stage: test script: - cat artifact.txt needs: - pipeline: $PARENT_PIPELINE_ID job: build_artifactsMulti-projet : needs:project
Section intitulée « Multi-projet : needs:project »Dans le pipeline aval :
test_downstream: stage: test script: - cat artifact.txt needs: - project: my/upstream_project job: build_artifacts ref: main artifacts: trueDéclencher un pipeline dans un autre projet
Section intitulée « Déclencher un pipeline dans un autre projet »Syntax project
Section intitulée « Syntax project »trigger_other_project: trigger: project: group/other-project branch: main strategy: dependAvec des variables
Section intitulée « Avec des variables »deploy_production: variables: DEPLOY_ENV: "production" APP_VERSION: $CI_COMMIT_TAG trigger: project: devops/deployment branch: main strategy: dependExemple monorepo
Section intitulée « Exemple monorepo »Structure :
monorepo/├── .gitlab-ci.yml # Parent├── frontend/│ ├── .gitlab-ci.yml # Enfant frontend│ └── src/├── backend/│ ├── .gitlab-ci.yml # Enfant backend│ └── src/└── shared/ └── utils/Parent (racine)
Section intitulée « Parent (racine) »stages: - prepare - build - deploy
# Déterminer ce qui a changéchanges: stage: prepare script: - | if git diff --name-only HEAD~1 | grep -q "^frontend/"; then echo "FRONTEND_CHANGED=true" >> build.env fi if git diff --name-only HEAD~1 | grep -q "^backend/"; then echo "BACKEND_CHANGED=true" >> build.env fi artifacts: reports: dotenv: build.env
# Déclencher frontend si modifiétrigger_frontend: stage: build needs: ["changes"] trigger: include: frontend/.gitlab-ci.yml strategy: depend rules: - if: $FRONTEND_CHANGED == "true"
# Déclencher backend si modifiétrigger_backend: stage: build needs: ["changes"] trigger: include: backend/.gitlab-ci.yml strategy: depend rules: - if: $BACKEND_CHANGED == "true"Enfant frontend
Section intitulée « Enfant frontend »stages: - install - build - test
install: stage: install script: npm ci cache: key: frontend-deps paths: - .npm/ variables: npm_config_cache: '$CI_PROJECT_DIR/.npm'
build: stage: build script: npm run build artifacts: paths: - dist/
test: stage: test script: npm testLimites et bonnes pratiques
Section intitulée « Limites et bonnes pratiques »| Limite | Valeur |
|---|---|
| Profondeur child pipelines (parent → child → grandchild) | 2 niveaux max |
| Taille de la hiérarchie downstream | 1000 pipelines par défaut (paramétrable) |
| Fichiers include par child pipeline | 3 fichiers max |
Bonnes pratiques
Section intitulée « Bonnes pratiques »-
Toujours
strategy: dependsauf si vous voulez explicitement ne pas attendre -
Un fichier CI par composant :
frontend/.gitlab-ci.yml,backend/.gitlab-ci.yml -
Conditions sur les triggers : ne déclenchez que ce qui a changé
-
Variables explicites : documentez ce que vous passez aux enfants
-
Nommez clairement :
trigger_frontend,trigger_backend, pasjob1,job2
Erreurs fréquentes
Section intitulée « Erreurs fréquentes »| Erreur | Cause | Solution |
|---|---|---|
| Parent passe en success mais enfant échoue | Manque strategy: depend | Ajouter strategy: depend ou mirror |
| Variable non trouvée dans l’enfant | Variable non passée | Utiliser variables: ou forward: |
maximum depth exceeded | Plus de 2 niveaux d’enfants | Restructurer le pipeline |
| Fichier enfant non trouvé | Mauvais chemin | Vérifier le chemin relatif |
| Artefacts non disponibles dans l’enfant | needs classique ne traverse pas les pipelines | Utiliser needs:pipeline:job |
needs:project échoue | Job token non autorisé | Configurer allowlist côté projet amont |
À retenir
Section intitulée « À retenir »trigger: includecrée un pipeline enfant à partir d’un fichier localstrategy: dependfait attendre le parent ;mirrorpour un reflet strictvariables:passe des variables à l’enfant- Artefacts : utilisez
needs:pipeline:job(parent→child) ouneeds:project(multi-projet) trigger: projectdéclenche un pipeline dans un autre projet- Limite : 2 niveaux de profondeur, 1000 pipelines downstream max
$CI_PIPELINE_SOURCEvautparent_pipelinedans un child pipeline