How can I get inject environment from a freestyle job in pipeline job

123 views
Skip to first unread message

stanle...@servicemax.com

unread,
Jun 27, 2017, 9:21:19 PM6/27/17
to Jenkins Users
Hello, all

I am trying to trigger a freestyle job in pipeline and need to get a inject environment from that job.
Before with flow job, we can use thing like 

c = build("test job1")
uuid = c.build.properties["environment"]["uuid"]

But I didn't find a way to do this similar in pipeline script.

Is there any hint on it?

Richard Ginga

unread,
Jun 28, 2017, 8:04:59 AM6/28/17
to jenkins...@googlegroups.com
The things you "can" get from the returned object (c) from a pipeline statement like: c = build job: "test job1" are here: 

https://github.com/jenkinsci/workflow-support-plugin/blob/master/src/main/java/org/jenkinsci/plugins/workflow/support/steps/build/RunWrapper.java

you might be able to do something with the non-whitelisted getRawBuild method.

Otherwise, to get that job's env variables you must do something "like" this: (untested)

Jenkins.instance.getItemByFullName("test job1").getAllJobs()[0].getLastSuccessfulBuild().getEnv("uuid")

--
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-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/fa73e7a7-ea85-4eee-8f8e-037689bff630%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Dick Ginga
Build Engineer

Stanley Shen

unread,
Jun 28, 2017, 1:14:50 PM6/28/17
to jenkins...@googlegroups.com
Thanks for replying.

I tried solution #1 you provided, but it report error like "org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use method”

For #2, it also report error like “org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use staticMethod jenkins.model.Jenkins getInstance”


Any idea on it.


Regards,
Stanley






You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/ouDKTknbt7k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAL3PpaVGzRL2j_rNYAhAsSPxw2F8gpotuLhpZiA3DOjkYXgDUw%40mail.gmail.com.

Richard Ginga

unread,
Jun 28, 2017, 1:24:26 PM6/28/17
to jenkins...@googlegroups.com
#1. try unclicking "Use Groovy sandbox" at the bottom of the script window.

#1 and #2 could be you don't have permissions. I am an admin of my jenkins master


To unsubscribe from this group and all its topics, send an email to jenkinsci-users+unsubscribe@googlegroups.com.

--
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-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Stanley Shen

unread,
Jun 28, 2017, 1:42:18 PM6/28/17
to jenkins...@googlegroups.com
Thanks, I didn’t notice the “Use Groovy sandbox”, and it works after I unchecked it.

println job.getRawBuild().getEnvironment()[“uuid"]
println Jenkins.instance.getItemByFullName(“test").getAllJobs()[0].getLastSuccessfulBuild().getEnvironment()["uuid"]

Both work for me.


Regards,
Stanley





To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAL3PpaV%2B6stTpw5P6HPftn9tgGrvKki%2Be%3DPYjxxDK%2BTGJM%2Bv4Q%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages