EnvInject Access to Manager

551 views
Skip to first unread message

Matt Felzani

unread,
Dec 19, 2012, 9:58:19 AM12/19/12
to jenkins...@googlegroups.com
Hi,

I'm trying to use the EnvInject plugin. Specifically in the "Prepare an environment for the run" > "Evaluated Groovy script" I want to be able to get access to the job's BUILD_NUMBER so that I can inject a variable that is partly composed of that value.

I've tried code like:
def manager = binding.getVariable("manager")
def buildNumber = manager.build.getEnvironment(manager.listener)['BUILD_NUMBER']

But I get an error of:
[EnvInject] - [ERROR] - SEVERE ERROR occurs: No such property: manager for class: groovy.lang.Binding

I've tried code like:
def buildNumber = manager.build.getEnvironment(manager.listener)['BUILD_NUMBER']

But I get an error of:
[EnvInject] - [ERROR] - SEVERE ERROR occurs: No such property: manager for class: Script1

Is the manager - via any API call - available at the time that script runs?

The following code works (and it returns the correct value), but i'm just trying to avoid having the Job's name (i.e. - "BnL Build") be hard-coded in the script:
def env = Jenkins.instance.getItem("BnL Build").getLastBuild().getEnvironment()
def buildNumber = env['BUILD_NUMBER']


Thanks in advance,
Matt

Grégory Boissinot

unread,
Dec 21, 2012, 6:52:15 PM12/21/12
to jenkins...@googlegroups.com
From EnvInject 1.75, you are able to use currentJob and currentBuild
variables in order to access respectively to Job and Run instances.

Matt Felzani

unread,
Dec 21, 2012, 9:37:32 PM12/21/12
to jenkins...@googlegroups.com
Wow, talk about service. Thanks a lot for adding that ... I'm using it already and loving it.

Eyal

unread,
Jul 2, 2013, 7:33:06 AM7/2/13
to jenkins...@googlegroups.com
So.. there's no access to manager?

Attention:
This e-mail and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error, please notify the sender immediately by replying to this message, and delete the original message from your system without making a copy. This e-mail is attributed to the sender and does not necessarily reflect the view of Markets Pulse P.S. Ltd. or any affiliate.

 

Please consider the environment before printing this email.

Daniel Beck

unread,
Jul 2, 2013, 10:26:58 AM7/2/13
to jenkins...@googlegroups.com
If by 'manager' you mean the object that gives you access to the Jenkins/Hudson instance, the current build, and the build listener, it's specific to Groovy Postbuild and doesn't exist in EnvInject.

https://github.com/jenkinsci/groovy-postbuild-plugin/blob/master/src/main/java/org/jvnet/hudson/plugins/groovypostbuild/GroovyPostbuildRecorder.java
> --
> 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.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Eyal Zfira

unread,
Jul 2, 2013, 10:36:35 AM7/2/13
to jenkins...@googlegroups.com
Yes, I meant that.

Is there a way to access the Jenkins/Hudson instance in EnvInject? I tried using Jenkins.getInstance() and it doesn't work.


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/Mtm9-eBJcMI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.

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





--
Eyal Zfira
Development Manager
Office: +972 9 95 44 551 |Fax: +972 9 95 44 553 
Skype: eyal_zfira_sk Site: www.marketspulse.com | 
 linkedin_icon.jpg 
Follow us on LinkedIn
Reply all
Reply to author
Forward
0 new messages