Skip to content

How to Wait for GitLab Downstream Pipelines Before Moving On in CI/CD Workflows

Downstream pipelines are a powerful feature of continuous integration (CI) platforms like GitLab. They allow you to trigger other projects within your repository, effectively creating dependencies between them during the build and deployment process. This can be particularly useful when managing multiple related web applications or microservices where one must depend on another’s output before deploying.

Here’s a common scenario: You have three separate GitLab project pipelines—Project A (web-frontend-1), Project B (web-frontend-2), and an e2e testing pipeline for your entire stack (Project C). Each of these projects builds Docker images, but they need to be completed before deploying or running tests.

Here’s what you might encounter:

stages:
  - build_testing
  - deploy
  - test
  
build-project-a-testing:
  stage: build_testing
  trigger:
    project: workspace/project-a
  variables:
    TESTING: true
    
# Repeat for Project B with respective parameters...

With the current configuration, each pipeline runs independently of others which may result in a deployed application not being up to date or test results potentially missing due to incomplete builds. This creates confusion and wastes valuable resources when trying to deploy outdated containers without corresponding e2e tests executed on top layer testing environment (Project C).

Solution: Using trigger_job with Dependency Strategy in .gitlab-ci.yml

To ensure that your build, test, or deployment stages only proceed after the downstream pipelines have completed successfully—use GitLab’s built-0in dependency strategy by adding it to a trigger job like so:

deploy-testing:
  stage: deploy_after_buildings
  tags: ["testing-runner"]
  script:
    - echo "Deploying after build is complete..."
  
trigger_jobs:
  stage: trigger_other_pipelines # Place this at the appropriate position in your stages.
  include: path/to/.gitlab-ci.yml of downstream projects (like Project A and B)
  strategy: depend

Here, deploy-testing is dependent on jobs from preceding triggers (trigger_jobs). This way when deployment stage runs, it already accounts for the completion statuses—thus ensuring that deployments are made only after successful builds. Similarly, tests will wait until build environments get a clean slate with latest images before proceeding in their respective pipelines (if you have orchestrated dependency ordering).

With this setup:

Remember that when dealing with multiple dependent pipelines, keeping them properly sequenced is key to a streamlined CI/CD process which relies heavily upon the correct flow of stages and interdependencies managed through GitLab’sefficient trigger jobs configuration strategy.


Previous Post
The Use and Impact of Common Workflow Language CW
Next Post
Why ctop Fails on Latest Docker Version Underst