Second job env_var_retrive_test looks for a variable from env_var_test dotenv variables and if the variable match the predefined value of the CICD rules, it triggers
With this setup, I tested them and could see the variables are correctly printing echo "[ $apple - $boy - $cat ]". However, the job was not triggering if I defined the variables in the rules section
rules:
- if: '$boy == "bar"'
when: always
Please correct me if I’m doing it wrong or help me with any better approach to do the same.
I’m not sure whether I’ve properly understood this, but I think what you’re trying to do is to write a file in the first test which contains some env vars, then use those env vars in the second job?
I think you maybe have two issues here. One is that artifacts:reports is for things like unit tests where you want the results to appear automatically on a merge request page, or on the pipeline Tests output. You want artifacts:paths here:
The second thing is that anything in a script section is essentially a Bash command.
I’m not sure whether your Docker container is doing something special with that deploy.env file, but if you want the contents to be used as environment variables, you will need to explicitly write something in the script or before_script of env_var_retrive_test to export those variables to the shell.
And the variables exported from the job env_var_test, wanted to make use under the rules: section of job env_var_retrive_test. The same variables are not required anywhere else in the second job and are only for deciding the env_var_retrive_test job to run on not based on the rules match.
Ah right, I didn’t know about dotenv variables, so my comments above are not relevant at all!
My guess is that maybe these variables aren’t available early enough in the CI job to be used by rules.
This issue is relevant to you, and I would suggest that you comment there and vote the issue up (which will make it more likely to be scheduled in an upcoming sprint).
I would guess though, that you’ll have to do something more complicated to get the pipeline behaviour you want, whilst that issue is still open.