Re: Reading Hudson and job environment variables from ParameterDefinition plugin

2017-09-20 Thread Paulo Eduardo Neves
Is it possible to access the job config.xml file from the
ParameterDefinition object? It would also solve my problem.

On Wed, Sep 20, 2017 at 1:01 PM, Paulo Eduardo Neves 
wrote:

> It is a parametrized job. I would like to get the Environment variables
> the job will use. I need it in the screen that appears after clicking the 
> "*build
> now"* button, but before clicking the form submission button that will
> start the construction process.
>
>
>
> On Wed, Sep 20, 2017 at 12:41 PM, Robert Sandell 
> wrote:
>
>> At build time your ParameterValue gets the build as a parameter to
>> buildEnvironment(Run build, EnvVars env), so you get it from
>> build.getParent() but maybe the vars are already added to env so you might
>> not need the code I showed above.
>>
>> If you need the job at job schedule time, e.g. when clicking build now it
>> get's a bit trickier. You can use the StaplerRequest to find the job from
>> the ancestor path.
>>
>> Job job = request.findAncestor(Job.class)
>>
>> But I don't think there is any good way to get it when constructing the
>> value from CliCommand, maybe the following could work
>>
>> if (command instanceof BuildCommand) {
>> Job job = (BuildCommand)command.job;
>> }
>>
>> /B
>>
>>
>> 2017-09-20 16:38 GMT+02:00 Paulo Eduardo Neves :
>>
>>> Thanks for your answer, Robert. Almost there!
>>>
>>>
>>> How would you create the job instance variable with the current job? I
>>> see that there is a model.Job class, but I'm too newbie and can't find
>>> how to instantiate it.
>>>
>>>
>>>
>>> Em quarta-feira, 20 de setembro de 2017 06:51:26 UTC-3, Robert Sandell
>>> escreveu:

 Something like this I'd guess

 SetEnvBuildWrapper wrapper = 
 job.getBuildWrappers().get(Jenkins.getInstance().getDescriptorByType(SetEnvBuildWrapper.DescriptorImpl.class))
 Map vars = wrapper.getLocalVarMap()

 /B

 2017-09-19 20:53 GMT+02:00 Paulo Eduardo Neves :

> Earlier today I post this message to Jenkin Users mailing list. I
> mistakenly though that it were the place for plugin questions. Sorry for
> the crosspost,
>
> I have a prebuild plugin that extends ParameterDefinition class. It
> just give me some options to prepare the build.
>
> It is an old installation and uses the deprecated SetEnv plugin
>  to setup a
> bunch of environment variables.
>
> Is it possible to access the environment variables defined in the *SetEnv
> plugin* from my plugin? It just creates the build object when the
> submit button is pressed, so I don't have access to it from my form.
>
> If I can access the configuration file, I can also parse these
> variables. Maybe this is easier to do.
>
> I also would like to access the Jenkins global variable values. If I
> do a System.getenv("JAVA_HOME") I get the value, but if I try with a
> variable defined in the SetEnv plugin or in the global configuration, it
> comes null.
>
> If you can point me an example or reference, it would be great.
>
> Thanks in advance for any help.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Jenkins Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to jenkinsci-de...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jenkinsci-dev/917dbdc6-d11
> d-4277-87d8-f85468213903%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



 --
 Robert Sandell
 *Software Engineer*
 *CloudBees Inc.*

>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Jenkins Developers" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to jenkinsci-dev+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>> gid/jenkinsci-dev/53457ddc-e051-49a7-846f-7c26b85c8b3a%40goo
>>> glegroups.com
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> Robert Sandell
>> *Software Engineer*
>> *CloudBees Inc.*
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Jenkins Developers" group.
>> To unsubscribe from this topic, visit https://groups.google.com/d/to
>> pic/jenkinsci-dev/2hLy525cxsg/unsubscribe.
>> To unsubscribe from this group and all 

Re: Reading Hudson and job environment variables from ParameterDefinition plugin

2017-09-20 Thread Paulo Eduardo Neves
It is a parametrized job. I would like to get the Environment variables the
job will use. I need it in the screen that appears after clicking the "*build
now"* button, but before clicking the form submission button that will
start the construction process.



On Wed, Sep 20, 2017 at 12:41 PM, Robert Sandell 
wrote:

> At build time your ParameterValue gets the build as a parameter to
> buildEnvironment(Run build, EnvVars env), so you get it from
> build.getParent() but maybe the vars are already added to env so you might
> not need the code I showed above.
>
> If you need the job at job schedule time, e.g. when clicking build now it
> get's a bit trickier. You can use the StaplerRequest to find the job from
> the ancestor path.
>
> Job job = request.findAncestor(Job.class)
>
> But I don't think there is any good way to get it when constructing the
> value from CliCommand, maybe the following could work
>
> if (command instanceof BuildCommand) {
> Job job = (BuildCommand)command.job;
> }
>
> /B
>
>
> 2017-09-20 16:38 GMT+02:00 Paulo Eduardo Neves :
>
>> Thanks for your answer, Robert. Almost there!
>>
>>
>> How would you create the job instance variable with the current job? I
>> see that there is a model.Job class, but I'm too newbie and can't find
>> how to instantiate it.
>>
>>
>>
>> Em quarta-feira, 20 de setembro de 2017 06:51:26 UTC-3, Robert Sandell
>> escreveu:
>>>
>>> Something like this I'd guess
>>>
>>> SetEnvBuildWrapper wrapper = 
>>> job.getBuildWrappers().get(Jenkins.getInstance().getDescriptorByType(SetEnvBuildWrapper.DescriptorImpl.class))
>>> Map vars = wrapper.getLocalVarMap()
>>>
>>> /B
>>>
>>> 2017-09-19 20:53 GMT+02:00 Paulo Eduardo Neves :
>>>
 Earlier today I post this message to Jenkin Users mailing list. I
 mistakenly though that it were the place for plugin questions. Sorry for
 the crosspost,

 I have a prebuild plugin that extends ParameterDefinition class. It
 just give me some options to prepare the build.

 It is an old installation and uses the deprecated SetEnv plugin
  to setup a
 bunch of environment variables.

 Is it possible to access the environment variables defined in the *SetEnv
 plugin* from my plugin? It just creates the build object when the
 submit button is pressed, so I don't have access to it from my form.

 If I can access the configuration file, I can also parse these
 variables. Maybe this is easier to do.

 I also would like to access the Jenkins global variable values. If I do
 a System.getenv("JAVA_HOME") I get the value, but if I try with a variable
 defined in the SetEnv plugin or in the global configuration, it comes null.

 If you can point me an example or reference, it would be great.

 Thanks in advance for any help.

 --
 You received this message because you are subscribed to the Google
 Groups "Jenkins Developers" group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to jenkinsci-de...@googlegroups.com.
 To view this discussion on the web visit https://groups.google.com/d/ms
 gid/jenkinsci-dev/917dbdc6-d11d-4277-87d8-f85468213903%40goo
 glegroups.com
 
 .
 For more options, visit https://groups.google.com/d/optout.

>>>
>>>
>>>
>>> --
>>> Robert Sandell
>>> *Software Engineer*
>>> *CloudBees Inc.*
>>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Jenkins Developers" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to jenkinsci-dev+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/jenkinsci-dev/53457ddc-e051-49a7-846f-7c26b85c8b3a%40googlegroups.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> Robert Sandell
> *Software Engineer*
> *CloudBees Inc.*
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Jenkins Developers" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/jenkinsci-dev/2hLy525cxsg/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> jenkinsci-dev+unsubscr...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/jenkinsci-dev/CALzHZS2w6UZ0bBOCaJnLs3rNvSCLb
> st35KxUUuM62Hom3Az3ug%40mail.gmail.com
> 

Re: Reading Hudson and job environment variables from ParameterDefinition plugin

2017-09-20 Thread Robert Sandell
At build time your ParameterValue gets the build as a parameter to
buildEnvironment(Run build, EnvVars env), so you get it from
build.getParent() but maybe the vars are already added to env so you might
not need the code I showed above.

If you need the job at job schedule time, e.g. when clicking build now it
get's a bit trickier. You can use the StaplerRequest to find the job from
the ancestor path.

Job job = request.findAncestor(Job.class)

But I don't think there is any good way to get it when constructing the
value from CliCommand, maybe the following could work

if (command instanceof BuildCommand) {
Job job = (BuildCommand)command.job;
}

/B


2017-09-20 16:38 GMT+02:00 Paulo Eduardo Neves :

> Thanks for your answer, Robert. Almost there!
>
>
> How would you create the job instance variable with the current job? I
> see that there is a model.Job class, but I'm too newbie and can't find
> how to instantiate it.
>
>
>
> Em quarta-feira, 20 de setembro de 2017 06:51:26 UTC-3, Robert Sandell
> escreveu:
>>
>> Something like this I'd guess
>>
>> SetEnvBuildWrapper wrapper = 
>> job.getBuildWrappers().get(Jenkins.getInstance().getDescriptorByType(SetEnvBuildWrapper.DescriptorImpl.class))
>> Map vars = wrapper.getLocalVarMap()
>>
>> /B
>>
>> 2017-09-19 20:53 GMT+02:00 Paulo Eduardo Neves :
>>
>>> Earlier today I post this message to Jenkin Users mailing list. I
>>> mistakenly though that it were the place for plugin questions. Sorry for
>>> the crosspost,
>>>
>>> I have a prebuild plugin that extends ParameterDefinition class. It just
>>> give me some options to prepare the build.
>>>
>>> It is an old installation and uses the deprecated SetEnv plugin
>>>  to setup a
>>> bunch of environment variables.
>>>
>>> Is it possible to access the environment variables defined in the *SetEnv
>>> plugin* from my plugin? It just creates the build object when the
>>> submit button is pressed, so I don't have access to it from my form.
>>>
>>> If I can access the configuration file, I can also parse these
>>> variables. Maybe this is easier to do.
>>>
>>> I also would like to access the Jenkins global variable values. If I do
>>> a System.getenv("JAVA_HOME") I get the value, but if I try with a variable
>>> defined in the SetEnv plugin or in the global configuration, it comes null.
>>>
>>> If you can point me an example or reference, it would be great.
>>>
>>> Thanks in advance for any help.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Jenkins Developers" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to jenkinsci-de...@googlegroups.com.
>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>> gid/jenkinsci-dev/917dbdc6-d11d-4277-87d8-f85468213903%40goo
>>> glegroups.com
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> Robert Sandell
>> *Software Engineer*
>> *CloudBees Inc.*
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Jenkins Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to jenkinsci-dev+unsubscr...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/jenkinsci-dev/53457ddc-e051-49a7-846f-7c26b85c8b3a%
> 40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Robert Sandell
*Software Engineer*
*CloudBees Inc.*

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/CALzHZS2w6UZ0bBOCaJnLs3rNvSCLbst35KxUUuM62Hom3Az3ug%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Reading Hudson and job environment variables from ParameterDefinition plugin

2017-09-20 Thread Robert Sandell
Something like this I'd guess

SetEnvBuildWrapper wrapper =
job.getBuildWrappers().get(Jenkins.getInstance().getDescriptorByType(SetEnvBuildWrapper.DescriptorImpl.class))
Map vars = wrapper.getLocalVarMap()

/B

2017-09-19 20:53 GMT+02:00 Paulo Eduardo Neves :

> Earlier today I post this message to Jenkin Users mailing list. I
> mistakenly though that it were the place for plugin questions. Sorry for
> the crosspost,
>
> I have a prebuild plugin that extends ParameterDefinition class. It just
> give me some options to prepare the build.
>
> It is an old installation and uses the deprecated SetEnv plugin
>  to setup a bunch
> of environment variables.
>
> Is it possible to access the environment variables defined in the *SetEnv
> plugin* from my plugin? It just creates the build object when the submit
> button is pressed, so I don't have access to it from my form.
>
> If I can access the configuration file, I can also parse these variables.
> Maybe this is easier to do.
>
> I also would like to access the Jenkins global variable values. If I do
> a System.getenv("JAVA_HOME") I get the value, but if I try with a variable
> defined in the SetEnv plugin or in the global configuration, it comes null.
>
> If you can point me an example or reference, it would be great.
>
> Thanks in advance for any help.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Jenkins Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to jenkinsci-dev+unsubscr...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/jenkinsci-dev/917dbdc6-d11d-4277-87d8-f85468213903%
> 40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Robert Sandell
*Software Engineer*
*CloudBees Inc.*

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/CALzHZS3g4dv2r-40NiisAJayuNiLLdW%3DHcKk%3DGbXpamSrF65WA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.