Sandbox is preventing me from formatting a string

2019-02-18 06:33发布

I have a simple groovy script:

node ("master")
{
  echo "I am about to try to use String.format"
  def jjj = String.format("bob")
  echo jjj 
}

If I put this script right into my job configuration and run it, it runs fine.

But if I put that script into a file which I then load via "Workflow script from SCM", I get the error

org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: unclassified staticMethod java.lang.String format java.lang.String

How do I work around this? Is it possible to turn off the sandbox for "Workflow script from SCM" like it is for "Workflow script"?

Or is there some sandbox-approved way of formatting a string in groovy?

And why is it preventing me from formatting a string in the first place?

2条回答
做个烂人
2楼-- · 2019-02-18 07:13

How do I work around this?

Possibly (untested)

String.format("bob", [])

rather than using varargs. At any rate you should file a bug in JIRA (component script-security-plugin, label workflow) with steps to reproduce.

Is it possible to turn off the sandbox for "Workflow script from SCM" like it is for "Workflow script"?

No: JENKINS-28178

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-02-18 07:23

I think it's not possible to disable sandboxing when using Workflow script from SCM

However you can approve the usage here:

http://<jenkins_host>:<port>/scriptApproval/
查看更多
登录 后发表回答