
Module 4 Lesson 1: Multi-Project Pipelines
Connect the dots. Learn how to trigger pipelines in other projects, creating a cross-service automation workflow for complex microservice architectures.
Module 4 Lesson 1: Multi-Project Pipelines
In a microservice architecture, one "Push" might need to trigger several other projects.
- Scenario: You update the "Auth Library" in
project-a. - The Need: Now, the "Payment Service" in
project-bmust automatically rebuild to use the new library.
This is called a Downstream Pipeline.
1. The trigger Keyword
To start a pipeline in a different project, use the trigger keyword.
trigger-payment-build:
stage: deploy
trigger:
project: my-company/payment-service # The path to the other repo
branch: main # Which branch to start?
2. Passing Variables to Downstream
You can send instructions to the other project using variables.
trigger-payment-build:
variables:
SOURCE_PROJECT: $CI_PROJECT_NAME
NEW_VERSION: $CI_COMMIT_TAG
trigger: my-company/payment-service
3. "Upstream" vs "Downstream"
- Upstream: The project that starts the process (The Triggerer).
- Downstream: The project that responds to the call (The Triggered).
In GitLab, the "Upstream" pipeline can wait for the "Downstream" one to finish before marking itself as "Success" by using strategy: depend.
Visualizing Multi-Project Pipeline Flow
graph LR
subgraph "Project Alpha (Upstream)"
A1[Code Push] --> A2[Build]
A2 --> A3[Test]
A3 --> A4[Trigger Job]
end
A4 -->|trigger| B1
subgraph "Project Beta (Downstream)"
B1[Triggered Build] --> B2[Run Tests]
B2 --> B3[Deploy]
end
B3 -.->|strategy: depend| A4
A4 --> A5[Mark Success/Fail]
4. Why Use This?
- Isolation: Every team keeps their own
.gitlab-ci.yml. They don't have to merge their code into one massive "Monorepo." - Versioning: You can trigger the downstream project to only run tests against your "Alpha" version, keeping the "Stable" version safe.
- Complex Deployments: Use one "Gateway" project to deploy 10 different apps at the same time.
Exercise: The Chain Reaction
- Create two separate projects in GitLab:
Project AlphaandProject Beta. - In
Project Alpha, create a job that triggers a pipeline inProject Beta. - Add
strategy: dependto the trigger job. - In
Project Beta, add a simpletestjob. - Run Alpha's pipeline. Check the graph. Do you see the "Downstream" pipeline listed there?
- If
Project Betafails, doesProject Alphaalso show as "Failed"? (Check thestrategyeffect).
Summary
Multi-project pipelines turn your individual automation scripts into a "System of Systems." By mastering triggers, you can orchestrate complex releases that involve multiple teams and repositories across your whole company.
Next Lesson: Internal organization: Parents and Child Pipelines.