Token Macro expansion doesn't seem to be supported in job parameters

650 views
Skip to first unread message

Paul Sokolovsky

unread,
Aug 19, 2014, 9:19:58 AM8/19/14
to jenkin...@googlegroups.com
Hello,

I'm trying to take a value as produced by some plugin's token macro
support and inject it into job's build, so eventually it is available
in slave's environment to a shell script.

After some thinking, an obvious way to achieve that seems to make a job
parametrized, and just set its default value to be token expansion. For
definitiveness, let's take Scriptler token macro support as an example
(https://wiki.jenkins-ci.org/display/JENKINS/Scriptler+Plugin#ScriptlerPlugin-TokenMacroSupport).
So, for a job I define parameter "PARAM" with default value
"${SCRIPTLER, scriptId="superscript.groovy"}".

However, after running such job, I see that PARAM gets literal value of
"${SCRIPTLER, scriptId="superscript.groovy"}", i.e. token macro
expansion doesn't happen.

It actually took me quite some effort to be able to see macro expansion
in works - to make sure it works in general (I filed
https://issues.jenkins-ci.org/browse/JENKINS-24325 along the way). It
does - there're contexts in which the above macro properly expands.

That makes me to conclude that token macro expansion doesn't work in
job parameters. Am I doing something wrong? Any suggestions to resolve
this?


Thanks,

--
Best Regards,
Paul

Linaro.org | Open source software for ARM SoCs
Follow Linaro: http://www.facebook.com/pages/Linaro
http://twitter.com/#!/linaroorg - http://www.linaro.org/linaro-blog

Slide

unread,
Aug 19, 2014, 10:05:45 AM8/19/14
to Jenkins Developer List
You are correct. Token macro expansion only happens if it is explicitly used in the code that uses the value on the server side. Most fields in Jenkins don't do token macro expansion. The EnvInject may allow you to do something like what you want.


--
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.
For more options, visit https://groups.google.com/d/optout.



--
Website: http://earl-of-code.com

Paul Sokolovsky

unread,
Aug 19, 2014, 11:37:01 AM8/19/14
to jenkin...@googlegroups.com
On Tue, 19 Aug 2014 07:05:40 -0700
Slide <slide...@gmail.com> wrote:

> You are correct. Token macro expansion only happens if it is
> explicitly used in the code that uses the value on the server side.
> Most fields in Jenkins don't do token macro expansion. The EnvInject
> may allow you to do something like what you want.

Thanks for confirmation. Then, this looks like a bug for me. Well, on
second thought, token macro expansion is provided by a plugin, while
job params is a core feature. But well, lot of things were split from
core in last versions of Jenkins, why features which are truly global
and reusable can't go in opposite direction and be merged into core?

Are there other concerns which I may be missing (security, whatever)
with support for macro expansion in job params? Otherwise, I'll file a
bug.

Thanks for hint about EnvInject, I intended to look into it too. The
issue, I wanted to wrote plugin-like functionality in Groovy. And
indeed, it's possible and easy. But then integrating it into Jenkins in
secure and user-friendly manner appear to cause more trouble and
headache than writing a plugin in Java ;-(.

Slide

unread,
Aug 19, 2014, 11:40:40 AM8/19/14
to Jenkins Developer List
I don't think that the token macro stuff should be integrated into the core. There are other ways of generating parameter values to pass along, I believe the EnvInject plugin is the way to go. Integrating Token Macro into core is not going to happen.

Paul Sokolovsky

unread,
Aug 22, 2014, 3:07:23 PM8/22/14
to Slide, Jenkins Developer List
Hello,

On Tue, 19 Aug 2014 08:40:35 -0700
Slide <slide...@gmail.com> wrote:

> I don't think that the token macro stuff should be integrated into the
> core. There are other ways of generating parameter values to pass
> along, I believe the EnvInject plugin is the way to go. Integrating
> Token Macro into core is not going to happen.

So, I tried EnvInject plugin and didn't see it able to expand macros
like "${SCRIPTLER, scriptId="superscript.groovy"}" (they go literally).
Looking at
https://wiki.jenkins-ci.org/display/JENKINS/EnvInject+Plugin ,
TokenMacro plugin is not listed in dependencies. I also grepped thru
EnvInject source code and don't see code sequences required to expand
code macros, as specified on
https://wiki.jenkins-ci.org/display/JENKINS/Token+Macro+Plugin page.

[]

Slide

unread,
Aug 22, 2014, 3:37:40 PM8/22/14
to Paul Sokolovsky, Jenkins Developer List
One option might be to use the token macro in a groovy script from the EnvInject (I believe it supports groovy scripts for setting variables). I don't know of any other way of doing it.
Reply all
Reply to author
Forward
0 new messages