Help! Facing an issue while setting condition for a job

Hi all,

I am a newbie to Gitlab and I’m having an issue while configuring condition to run a job.

This is my requirement, I have a 2 jobs in my pipeline. One is initial_job. This will trigger when there is a commit on dev branch and generate a value with either true or false and assign in into a variable call CAN_RUN. And my second job is test_job. This second job will trigger after the completion of my initial_job additionally it should have these conditions/rules as well. The branch should be dev and CAN_RUN variable’s value should be true.

I tried this method metioned in here Pass an environment variable to another job. to pass the CAN_RUN variable into my test_job. But I got some error related to upload artifact. It’s like this To fix that I set RUNNER_GENERATE_ARTIFACTS_METADATA: "false". But no luck.

Then I got an idea to save the value via API request in newly created CI/CD variable in gitlab(CAN_RUN - same name). The below shown is the pipeline

initial_job:
stage: dev
script:
// This job will generate a value(true/false) and assign the value into a CI/CD variable($CAN_RUN) via rest-endpoint
only:
refs:
- dev

test_job:
stage: dev
needs:
- initial_job
script:
// to run
rules:
- if: ($CI_COMMIT_BRANCH == “dev” && $CAN_RUN == “true”)
when: always

Actually, this is also not working. It took the value for CAN_RUN from the previous pipeline’s run so this is not working as I expected. I would appreciate if anyone help me to sort this out. Thanks in advance.

Regards,
Khopi