Alternative to EnvInject?

447 views
Skip to first unread message

Niksan

unread,
May 25, 2016, 9:14:03 AM5/25/16
to Jenkins Users
I'm trying to inject a variable in to a job mid-flight who triggers another job and waits for it, 'inject environment variables' seems to do what I want with the caveat being it doesn't appear to do parameter substitution.

My build step does :

build.addAction(new ParametersAction([ new StringParameterValue("SomeVar", "SomeValue) ] ))

And I want this to be available on a child node job, like I say, the inject build step works but is not able to tackle substitution, I even tried having the parameter action as a single server groovy script build step hoping when the build step had finished the env variables would have been updated, but doesn't seem to be the case.

So, what alternatives are they to accomplish this task?

Eric Pyle

unread,
May 25, 2016, 11:11:09 AM5/25/16
to jenkins...@googlegroups.com

IIRC, you can save the parameter value into a file (e.g. echo MYPARAM=$MYPARAM > params.txt), and EnvInject can read it from there. Not pretty, but should work.

Eric

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/1cab60e8-2acd-47fe-ad8b-67a41cd12a33%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Niksan

unread,
May 25, 2016, 11:25:42 AM5/25/16
to Jenkins Users
Messy indeed. :)

Well, with luck I stumbled across this. https://themettlemonkey.wordpress.com/2014/10/03/programmatically-set-jenkins-build-variables/
And a bit of digging was able to utilize the EnvInject's plugin EnvInjectBuilderContributionAction.

That left me with a more flexible and sane way to deal with this as a groovy script.

import hudson.model.*
import org.jenkinsci.plugins.envinject.EnvInjectBuilderContributionAction

def params = [ 'SomeName' : 'SomeValue' ]
build
.addAction(new EnvInjectBuilderContributionAction(params ))

Cheers.


Reply all
Reply to author
Forward
0 new messages