Answers: <p>You could use dynamic child pipelines. (<a href="https://docs.gitlab.com/ee/ci/parent_child_pipelines.html#dynamic-child-pipelines" rel="nofollow noreferrer">https://docs.gitlab.com/ee/ci/parent_child_pipelines.html#dynamic-child-pipelines</a>).</p>
  <p>You could create a job for triggering your job &quot;buildArtifact&quot; in a yml-file created with jsonnet in your &quot;checkArtifactPresent&quot;.
  With using &quot;--ext-str&quot; or &quot;--ext-code&quot; in jsonnet.
  You can control the yml-file creation (<a href="https://jsonnet.org/learning/tutorial.html#parameterize-entire-config" rel="nofollow noreferrer">https://jsonnet.org/learning/tutorial.html#parameterize-entire-config</a>).</p>
  <p>Read more <a href="https://jsonnet.org/" rel="nofollow noreferrer">https://jsonnet.org/</a></p>
  
Answers: CC BY-SA 4.0
Answers: 2020-11-20T23:29:33.017Z
Answers: 2020-12-11T22:19:29.683Z
Answers: 2020-12-11T22:19:29.683Z
Answers: Jakob Liskow
Body: <p>I have this scenario where I want to run the trigger in build stage only when <code>$FLAG</code> variable has been set by the <code>.pre</code> stage. However, the <code>build</code> stage never runs.</p>
  <p>How should I conditionally trigger a downstream pipeline?</p>
  <pre><code>checkArtifactPresent:
    stage: .pre
    script:
      - &gt;
        set +e;
        if curl -s -S -f $NEXUS_RAW_PICKER_REPOSITORY/${PRODUCT_FLAVOR}/${PRODUCT_FLAVOR}-${BUILD_TYPE}v${PICKER_TEMPLATE_TAG}.apk --output ${PRODUCT_FLAVOR}-${BUILD_TYPE}v${PICKER_TEMPLATE_TAG}.apk;
        then
          export FLAG= true;
        fi
  
  buildArtifact:
    stage: build
    only:
     variables:
       - $FLAG
    trigger:
     project: dev/project_name
     strategy: depend
  </code></pre>
  
Tags: <continuous-integration><gitlab><continuous-deployment><gitlab-ci-runner>
Title: Trigger gitlab downstream pipeline from a upstream pipeline in a multi-project using trigger, rules and custom configuration variables
UserDisplayName: sd1517
ThreadText: # Trigger gitlab downstream pipeline from a upstream pipeline in a multi-project using trigger, rules and custom configuration variables
  
  (Asked by: username_0 on 2020-11-12)
  
  I have this scenario where I want to run the trigger in build stage only when `$FLAG` variable has been set by the `.pre` stage. However, the `build` stage never runs.
  
  How should I conditionally trigger a downstream pipeline?
  
  ```
  checkArtifactPresent:
    stage: .pre
    script:
      - >
        set +e;
        if curl -s -S -f $NEXUS_RAW_PICKER_REPOSITORY/${PRODUCT_FLAVOR}/${PRODUCT_FLAVOR}-${BUILD_TYPE}v${PICKER_TEMPLATE_TAG}.apk --output ${PRODUCT_FLAVOR}-${BUILD_TYPE}v${PICKER_TEMPLATE_TAG}.apk;
        then
          export FLAG= true;
        fi
  
  buildArtifact:
    stage: build
    only:
     variables:
       - $FLAG
    trigger:
     project: dev/project_name
     strategy: depend
  
  ```
  
  **Tags:** continuous-integration, gitlab, continuous-deployment, gitlab-ci-runner
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-11-20. Score: 1
  
  You could use dynamic child pipelines. (<https://docs.gitlab.com/ee/ci/parent_child_pipelines.html#dynamic-child-pipelines>).
  
  You could create a job for triggering your job "buildArtifact" in a yml-file created with jsonnet in your "checkArtifactPresent".
  With using "--ext-str" or "--ext-code" in jsonnet.
  You can control the yml-file creation (<https://jsonnet.org/learning/tutorial.html#parameterize-entire-config>).
  
  Read more <https://jsonnet.org/>
  
  
  ---
  
  