Accessing parameter values form a different plugin

20 views
Skip to first unread message

Jordan Vogel

unread,
Jun 5, 2019, 1:02:17 PM6/5/19
to Jenkins Developers
Hey, so I am trying to access the variable of the job parameter which comes though the Parameterized Build Jobs plugin. This variable is passed in through the URL of the script that triggers the job. I am writing a custom plugin to have some settings changes based on the parameter the job gets passed in. I, for the life of me, can't seem to access the variable, and I am thinking this is because it is a variable that comes from another plugin, not inherent to jenkins. 

I have tried System.getEnv(EnvVar), and System.getProperty(EnvVar) both to no avail, I have even tried to get an Array of all parameters, all of these return null. 

Does anyone know how this is done? Do I have to change functionality in the Parameterized Build Jobs plugin (not ideal). Or how can I access a job parameter passing in from the above plugin, from a separate plugin?

Thanks

Jeff Pearce

unread,
Jun 5, 2019, 1:12:19 PM6/5/19
to jenkin...@googlegroups.com

Assuming you have the current build project, It might be included in build.getParent().getProperties() https://javadoc.jenkins.io/hudson/model/Job.html#getProperties--

 

 

 

From: 'Jordan Vogel' via Jenkins Developers <jenkin...@googlegroups.com>
Reply-To: "jenkin...@googlegroups.com" <jenkin...@googlegroups.com>
Date: Wednesday, June 5, 2019 at 10:02 AM
To: Jenkins Developers <jenkin...@googlegroups.com>
Subject: Accessing parameter values form a different plugin

 

Notice: This email is from an external sender.

 

--
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/2637a384-e218-45e1-af1b-2951708a2f09%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jesse Glick

unread,
Jun 6, 2019, 8:22:51 AM6/6/19
to Jenkins Dev
On Wed, Jun 5, 2019 at 1:12 PM Jeff Pearce <jxpe...@godaddy.com> wrote:
> Assuming you have the current build project, It might be included in build.getParent().getProperties() https://javadoc.jenkins.io/hudson/model/Job.html#getProperties--

No, `Job.properties` is unrelated.

From: 'Jordan Vogel' via Jenkins Developers <jenkin...@googlegroups.com>
> I have tried System.getEnv(EnvVar), and System.getProperty(EnvVar) both to no avail

No, these are things set on the Jenkins JVM, nothing to do with build variables.

You want to get access to an `EnvVars` object. Depending on what
exactly you are doing, this might be passed in as a parameter to a
method you implement, etc. Your original description

> have some settings changes

is too vague to help with, I am afraid.

Jordan Vogel

unread,
Jun 6, 2019, 10:52:52 AM6/6/19
to Jenkins Developers
I'll try and give you some more specifics. Basically I am trying to access a parameter the jobs are passed when they are triggered by scripts. So the url for the POST request is my-dns.net/MyJobName/buildWithParameter
?parameterName=Value. I want to be able to access that value from a plugin. For example I would like to access that value within in the Perforce plugin so I can have some custom sync behaviors for changelists. The thing I am struggling with is I don't know where/how to access that parameter from a different plugin.

Thanks

Jeff Pearce

unread,
Jun 6, 2019, 12:39:56 PM6/6/19
to jenkin...@googlegroups.com

If I understand correctly, this code https://github.com/jenkinsci/github-autostatus-plugin/blob/daf4bf1a0553f91bb0b4deaee32905f077f050ec/src/main/java/org/jenkinsci/plugins/githubautostatus/BuildStatusJobListener.java#L83-L94

Is what you want – it puts all the parameters passed to a job into a map. It’s a different than what I wrote earlier, I was referencing broken code.

 

Best

Jeff

From: 'Jordan Vogel' via Jenkins Developers <jenkin...@googlegroups.com>
Reply-To: "jenkin...@googlegroups.com" <jenkin...@googlegroups.com>
Date: Thursday, June 6, 2019 at 7:53 AM
To: Jenkins Developers <jenkin...@googlegroups.com>
Subject: Re: Accessing parameter values form a different plugin

 

Notice: This email is from an external sender.

 

I'll try and give you some more specifics. Basically I am trying to access a parameter the jobs are passed when they are triggered by scripts. So the url for the POST request is my-dns.net/MyJobName/buildWithParameter

--

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.

Jesse Glick

unread,
Jun 6, 2019, 1:30:03 PM6/6/19
to Jenkins Dev
On Thu, Jun 6, 2019 at 10:53 AM 'Jordan Vogel' via Jenkins Developers
<jenkin...@googlegroups.com> wrote:
> I would like to access [a build parameter] value within in the Perforce plugin

Typically `build.getEnvironment(listener)` from an `SCM.checkout` override.
Reply all
Reply to author
Forward
0 new messages