Answers: <p>The strategy keyword is the solution :</p>
  <p>From the <a href="https://docs.gitlab.com/ee/ci/yaml/#triggerstrategy" rel="nofollow noreferrer">documentation</a> :</p>
  <blockquote>
  <pre class="lang-yml prettyprint-override"><code>trigger_job:
    trigger:
      include: path/to/child-pipeline.yml
      strategy: depend
  </code></pre>
  <p>In this example, jobs from subsequent stages wait for the triggered pipeline to successfully complete before starting.</p>
  </blockquote>
  
Answers: CC BY-SA 4.0
Answers: 2023-06-22T14:07:05.157Z
Answers: 2023-06-22T14:07:05.157Z
Answers: Lionep
Body: <p>I'm not sure this is the way to proceed, but I'm starting using downstream pipelines.<br />
  I have 3 projects :</p>
  <ul>
  <li>Project A : web-frontend-1</li>
  <li>Project B : web-frontend-2</li>
  <li>Project C : global-e2e-testing</li>
  </ul>
  <p>I'm setting up a CI pipeline on Project C which should do :</p>
  <ul>
  <li>Run main pipeline of Project A, with var TESTING=true (that is building docker images)</li>
  <li>Run main pipeline of Project B, with var TESTING=true (that is building docker images)</li>
  <li>Deploy on testing environment (it's pulling docker images, and relaunching project)</li>
  <li>Run e2e tests on testing environment</li>
  </ul>
  <p>Here is my Project C <code>.gitlab-ci.yml</code> (upstream pipeline) :</p>
  <pre class="lang-yml prettyprint-override"><code>stages:
  - build-testing
  - deploy
  - test
  
  build-project-a-testing:
    stage: build-testing
    trigger:
      project: workspace/project-a
    variables:
      TESTING: true
  
  build-project-b-testing:
    stage: build-testing
    trigger:
      project: workspace/project-b
    variables:
      TESTING: true
  
  deploy-testing:
    stage: deploy
    tags: [&quot;testing-runner&quot;]
    script:
      - echo &quot;deploying...&quot;
  
  playwright-firefox:
    stage: test
    before_script:
      - npm i
      - npx playwright install
    script:
      - npx playwright test --project=firefox --workers=1
    tags:
      - run-playwright
    artifacts:
      name: playwright-report-firefox
      paths:
        - playwright-report
        - results.xml
      reports:
        junit: results.xml
      expire_in: 1 week
      allow_failure: true
  </code></pre>
  <p>The issue I have is that the downstream pipeline are launched but without waiting them for ending.<br />
  So deployment job, would deploy an old container image, and testing is not relevant.</p>
  <p>Is there a way to wait for downstream pipeline to finish ?<br />
  I can &quot;reverse&quot; the order of which project is downstream / upstream, but since I have two projects to build, the issue would be the same.</p>
  
Tags: <gitlab><cicd><gitlab-ci-runner>
Title: How to wait for gitlab downstream pipelines to finish before going to next stage?
UserDisplayName: Lionep
ThreadText: # How to wait for gitlab downstream pipelines to finish before going to next stage?
  
  (Asked by: username_0 on 2023-06-22)
  
  I'm not sure this is the way to proceed, but I'm starting using downstream pipelines.  
  I have 3 projects :
  
  * Project A : web-frontend-1
  * Project B : web-frontend-2
  * Project C : global-e2e-testing
  
  I'm setting up a CI pipeline on Project C which should do :
  
  * Run main pipeline of Project A, with var TESTING=true (that is building docker images)
  * Run main pipeline of Project B, with var TESTING=true (that is building docker images)
  * Deploy on testing environment (it's pulling docker images, and relaunching project)
  * Run e2e tests on testing environment
  
  Here is my Project C `.gitlab-ci.yml` (upstream pipeline) :
  
  ```yml
  stages:
  - build-testing
  - deploy
  - test
  
  build-project-a-testing:
    stage: build-testing
    trigger:
      project: workspace/project-a
    variables:
      TESTING: true
  
  build-project-b-testing:
    stage: build-testing
    trigger:
      project: workspace/project-b
    variables:
      TESTING: true
  
  deploy-testing:
    stage: deploy
    tags: ["testing-runner"]
    script:
      - echo "deploying..."
  
  playwright-firefox:
    stage: test
    before_script:
      - npm i
      - npx playwright install
    script:
      - npx playwright test --project=firefox --workers=1
    tags:
      - run-playwright
    artifacts:
      name: playwright-report-firefox
      paths:
        - playwright-report
        - results.xml
      reports:
        junit: results.xml
      expire_in: 1 week
      allow_failure: true
  
  ```
  
  The issue I have is that the downstream pipeline are launched but without waiting them for ending.  
  So deployment job, would deploy an old container image, and testing is not relevant.
  
  Is there a way to wait for downstream pipeline to finish ?  
  I can "reverse" the order of which project is downstream / upstream, but since I have two projects to build, the issue would be the same.
  
  **Tags:** gitlab, cicd, gitlab-ci-runner
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2023-06-22. Score: 1 | Accepted answer
  
  The strategy keyword is the solution :
  
  From the [documentation](https://docs.gitlab.com/ee/ci/yaml/#triggerstrategy) :
  
  > ```yml
  > trigger_job:
  >   trigger:
  >     include: path/to/child-pipeline.yml
  >     strategy: depend
  >
  > ```
  >
  > In this example, jobs from subsequent stages wait for the triggered pipeline to successfully complete before starting.
  
  
  ---
  
  