Parsing user's input that contains Jenkins env variables

53 views
Skip to first unread message

Tal Yanai

unread,
Oct 21, 2019, 3:30:32 AM10/21/19
to Jenkins Developers
Hi,

Suppose I have made a plugin implementation (a step) that asks the user for a location (path) to a file on the disk.

When the user supply the value (using the job's configuration) he is using Jenkins variables/params such as ${JOB_NAME} as part of the path he supply.

So for example, an input can be looked like: /home/john/${JOB_NAME}/${BUILD_NUMBER}

Is there any Java library that know to return back the real value behind such input, so that I can farther user the real value within the plugin Java code?

Thanks,

Tal.

Gavin Mogan

unread,
Oct 21, 2019, 3:33:41 AM10/21/19
to jenkin...@googlegroups.com
For something like a freestyle plugin, I think you need to use the token macro plugin - https://wiki.jenkins.io/display/JENKINS/Token+Macro+Plugin
for pipeline, groovy will process the string before it gets to your code

--
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/a051d1b6-2ff7-4d93-846d-8bbcd426ef38%40googlegroups.com.

Slide

unread,
Oct 21, 2019, 11:00:24 AM10/21/19
to jenkin...@googlegroups.com
Token Macro will also work in pipeline jobs and does provide some additional benefit in that you can have code behind the macro that does some stuff for you that you would have to do manually (and possibly through either @NonCps or shared library). For something simple like a single parameter or environment value, a simple GString in groovy will do the trick. 



--

Tal Yanai

unread,
Oct 21, 2019, 12:35:21 PM10/21/19
to Jenkins Developers
Thanks a lot, Will try that...


On Monday, October 21, 2019 at 6:00:24 PM UTC+3, slide wrote:
Token Macro will also work in pipeline jobs and does provide some additional benefit in that you can have code behind the macro that does some stuff for you that you would have to do manually (and possibly through either @NonCps or shared library). For something simple like a single parameter or environment value, a simple GString in groovy will do the trick. 

On Mon, Oct 21, 2019 at 12:33 AM 'Gavin Mogan' via Jenkins Developers <jenkin...@googlegroups.com> wrote:
For something like a freestyle plugin, I think you need to use the token macro plugin - https://wiki.jenkins.io/display/JENKINS/Token+Macro+Plugin
for pipeline, groovy will process the string before it gets to your code

On Mon, Oct 21, 2019 at 12:30 AM Tal Yanai <t...@yanai.org.il> wrote:
Hi,

Suppose I have made a plugin implementation (a step) that asks the user for a location (path) to a file on the disk.

When the user supply the value (using the job's configuration) he is using Jenkins variables/params such as ${JOB_NAME} as part of the path he supply.

So for example, an input can be looked like: /home/john/${JOB_NAME}/${BUILD_NUMBER}

Is there any Java library that know to return back the real value behind such input, so that I can farther user the real value within the plugin Java code?

Thanks,

Tal.

--
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 jenkin...@googlegroups.com.

--
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 jenkin...@googlegroups.com.

Tal Yanai

unread,
Oct 21, 2019, 12:36:07 PM10/21/19
to Jenkins Developers
Thanks Gavin,


On Monday, October 21, 2019 at 6:00:24 PM UTC+3, slide wrote:
Token Macro will also work in pipeline jobs and does provide some additional benefit in that you can have code behind the macro that does some stuff for you that you would have to do manually (and possibly through either @NonCps or shared library). For something simple like a single parameter or environment value, a simple GString in groovy will do the trick. 

On Mon, Oct 21, 2019 at 12:33 AM 'Gavin Mogan' via Jenkins Developers <jenkin...@googlegroups.com> wrote:
For something like a freestyle plugin, I think you need to use the token macro plugin - https://wiki.jenkins.io/display/JENKINS/Token+Macro+Plugin
for pipeline, groovy will process the string before it gets to your code

On Mon, Oct 21, 2019 at 12:30 AM Tal Yanai <t...@yanai.org.il> wrote:
Hi,

Suppose I have made a plugin implementation (a step) that asks the user for a location (path) to a file on the disk.

When the user supply the value (using the job's configuration) he is using Jenkins variables/params such as ${JOB_NAME} as part of the path he supply.

So for example, an input can be looked like: /home/john/${JOB_NAME}/${BUILD_NUMBER}

Is there any Java library that know to return back the real value behind such input, so that I can farther user the real value within the plugin Java code?

Thanks,

Tal.

--
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 jenkin...@googlegroups.com.

--
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 jenkin...@googlegroups.com.

Jesse Glick

unread,
Oct 21, 2019, 2:07:29 PM10/21/19
to Jenkins Dev
On Mon, Oct 21, 2019 at 11:00 AM Slide <slide...@gmail.com> wrote:
> Token Macro will also work in pipeline jobs

Perhaps, but I would not recommend it.

https://jenkins.io/doc/developer/plugin-development/pipeline-integration/#variable-substitutions
Reply all
Reply to author
Forward
0 new messages