Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sandbox is preventing me from formatting a string

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?

like image 858
PortMan Avatar asked Dec 04 '22 02:12

PortMan


2 Answers

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/
like image 64
vehovmar Avatar answered Mar 07 '23 04:03

vehovmar


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

like image 31
Jesse Glick Avatar answered Mar 07 '23 05:03

Jesse Glick