Numeric Jenkins Pipeline Parameters

698 views
Skip to first unread message

Dave Hallam

unread,
Feb 2, 2018, 11:13:32 AM2/2/18
to Jenkins Users
Hi,

We have "string", "booleanParam", "choice", etc. but nothing for numeric types.  Is there a reason why not?

I have a pipeline where I would like a parameter to be a duration (in hours) to invoke a "sleep" step. 

Using "string" doesn't work because sleep is expecting an int. And if I try using a "script" step, I need to convert hours to seconds but I can't invoke toFloat() and toInt() because I get 
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use staticMethod org.codehaus.groovy.runtime.DefaultGroovyMethods toFloat java.lang.String


I know I could disable the sandbox for the latter issue, but I'd rather not - it would make more sense to be able to provide a numeric type to the pipeline in the first place.  Or maybe for the Sleep step to try to coerce the string to an int via DescribableModel.java.

Many thanks,

Dave


Daniel Beck

unread,
Feb 2, 2018, 11:39:07 AM2/2/18
to Jenkins Users

> On 2. Feb 2018, at 17:12, Dave Hallam <sna...@gmail.com> wrote:
>

> Is there a reason why not?

No such parameter type in Jenkins (without plugins) -- wouldn't make sense for other job types that typically receive values and env vars anyway.

> I know I could disable the sandbox for the latter issue, but I'd rather not - it would make more sense to be able to provide a numeric type to the pipeline in the first place. Or maybe for the Sleep step to try to coerce the string to an int via DescribableModel.java.

You could also approve (as admin) the use of this method via Manage Jenkins » In-Process Script Approval.

Would also make a good addition to https://github.com/jenkinsci/script-security-plugin/blob/master/src/main/resources/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/generic-whitelist -- toInteger is already whitelisted, these are not.

Reply all
Reply to author
Forward
0 new messages