I would like a trigger job to run or not depending on some variable that I set before. Is that possible?
In other words, I want something like this:
job1:
stage: stage1
script:
- (some stuff)
- TRIGGER_NEXT=(depends on above)
- echo "TRIGGER_NEXT=$TRIGGER_NEXT" >> vars.env
artifacts:
reports:
dotenv: vars.env
job2:
stage: stage2
rules:
- if: $TRIGGER_NEXT == "true"
trigger:
project: 'my-other-project'
strategy: depend
Sadly this doesn’t work, because (afaik) the rules in job2
are evaluated before job1 runs.
My current “solution” is to resort to an API call instead of using trigger
:
job1+2:
stage: stage1+2
script:
- (some stuff)
- TRIGGER_NEXT=(depends on above)
- >
if [[ "${TRIGGER_NEXT}" == 'true' ]] ; then
curl --fail --request POST --form token="${CI_JOB_TOKEN}" "${CI_API_V4_URL}/projects/${OTHER_PROJECT_ID}/trigger/pipeline"
fi
This works fine, but I am not completely satisfied because I want the strategy: depend
(i.e. job is marked as successful only after downstream pipeline succeeds).
I can’t think of a way (even hacky) to do what I want with the current possibilities of Gitlab, but maybe I’m not thinking of something?