Variable substitution in Jenkins plugin

57 views
Skip to first unread message

pa...@pholding.co.uk

unread,
May 30, 2015, 11:41:35 AM5/30/15
to jenkin...@googlegroups.com

I'm developing a new Jenkins plugin that will be executed during the build phase of a Jenkins job and have a requirement to allow the user to specify a variable name (as opposed to a literal value) in the job configuration for the plugin. The intention is that when the job executes the variable name specified by the user will then be substituted with the real value associated with the variable and that the plugin will then use this real value when running the perform method.

For example if the variable MY_VARIABLE with the value myValue was injected into the build environment by another part of job and the value ${MY_VARIABLE} was specified in the job configuration for my plugin, then I would like the plugin to substitute ${MY_VARIABLE} with the real value for the variable which is myValue.

enter image description here

Having done some research I understand that Jenkins does not automatically substitute variable in the job configuration for their respective values and this must be handled by the plugin. What I haven't been able to work out is the best way to perform the substitution in my plugin. The only solution I've found so far is the parse the string passed from the job configuration to see whether it matches the correct pattern for a variable and then lookup the value in my code.

Does the Jenkins API provide a better solution that would allow my plugin to substitute a variable with a real value when the build job is executed?

Daniel Beck

unread,
May 31, 2015, 2:29:47 PM5/31/15
to jenkin...@googlegroups.com

On 30.05.2015, at 17:41, pa...@pholding.co.uk wrote:

> Does the Jenkins API provide a better solution that would allow my plugin to substitute a variable with a real value when the build job is executed?

http://javadoc.jenkins-ci.org/hudson/EnvVars.html#expand%28java.lang.String%29

Adrien Lecharpentier

unread,
May 31, 2015, 3:54:29 PM5/31/15
to jenkin...@googlegroups.com

Hello,

You can also use the token macro plugin to do such things: https://wiki.jenkins-ci.org/display/JENKINS/Token+Macro+Plugin

-- Adrien


--
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/EA1537DF-CAEF-409F-8F07-36186DCB1535%40beckweb.net.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages