1

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
sd1517
  • 607
  • 4
  • 7
  • 23

1 Answers1

2

You can make use of Gitlab web api for Triggering pipelines through API

You can make use of trigger variables. You can apply conditions and then trigger the downstream job.

Here you can find a simple example:

https://docs.gitlab.com/ee/ci/triggers/#making-use-of-trigger-variables

Sourav
  • 3,025
  • 2
  • 13
  • 29
  • Yes, i found that, but the issue is that then the upstream pipeline does not wait for the downstream pipeline to complete. Well, I am in the process of writing a script to make the upstream pipeline to wait. I guess with the current version of gitlab there is no feature while using rules right ? – sd1517 Nov 13 '20 at 09:14