0

I have 2 Jenkins jobs namely test-trigger1 and test-trigger2 and I want to set up test-trigger1 to trigger test-trigger2 using an injected environment variable.

So in test-trigger1's Configure->Build Environment->Inject environment variables to the build process->Properties Content box I have this

enter image description here

Then I added a Build->Execute Shell step, which simply has

enter image description here

and a subsequent Build->Conditional step(single) step that has

enter image description here

However, I'm not triggering the test-trigger2 job, and I see this in test-trigger1's console output

(Steps for SCM checkout ommitted)
Run condition [Boolean condition] enabling prebuild for step [Trigger/call builds on other projects]
[EnvInject] - Executing scripts and injecting environment variables after the SCM step.
[EnvInject] - Injecting as environment variables the properties content 
TRIGGER_JOB=false

[EnvInject] - Variables injected successfully.
[test-trigger1] $ /bin/sh -xe /tmp/jenkins5417082998696567335.sh
+ echo TRIGGER_JOB=false
TRIGGER_JOB=false
+ TRIGGER_JOB=true
+ echo TRIGGER_JOB=true
TRIGGER_JOB=true
[Boolean condition] checking [false] against [^(1|y|yes|t|true|on|run)$] (origin token: ${ENV,var="TRIGGER_JOB"})
Run condition [Boolean condition] preventing perform for step [Trigger/call builds on other projects]
Notifying upstream projects of job completion
[Boolean condition] checking [false] against [^(1|y|yes|t|true|on|run)$] (origin token: ${ENV,var="TRIGGER_JOB"})
Run condition [Boolean condition] preventing perform for step [Builder to mark whether executed]
Finished: SUCCESS

Apparently, the Execute shell step is not setting the injected environment variable correctly, or I'm not setting it correctly? Any ideas on how I can make this work?

Chris F
  • 14,337
  • 30
  • 94
  • 192
  • when you update an environment variable in the shell session it applies on in that session and doesn't affect the Jenkins job, if you want it to take affect you will have to create the parameters in a file and inject them to your build. The question however is how to you want to control the value of the trigger job parameter? – Noam Helmer Jun 10 '22 at 14:27
  • Thanks Noam. "How do I want to control the value of the TRIGGER_JOB parameter you mean? I need to be able to set its value in an "Execute shell" job. Note above code is a prototype of the real job I have, but if I can make above code work, I can use the solution in my real-world job. – Chris F Jun 12 '22 at 15:54
  • In that case check out [This Answer](https://stackoverflow.com/a/10626193/13110835) it explains how to use the [EnvInject plugin](https://wiki.jenkins-ci.org/display/JENKINS/EnvInject+Plugin) to achieve what you want. – Noam Helmer Jun 13 '22 at 08:18

0 Answers0