Hi,
As the inline documentation (see the question marks on the right), this is
because your code runs in sandboxed mode/you're not an admin:
if *Use Groovy Sandbox* is checked, or you are not an administrator, not
all APIs will be available.

(Though I somehow agree that at first sight StringBuilder could be
whitelisted).

About sharing libraries, I guess this doc could help:
https://github.com/jenkinsci/workflow-plugin/blob/master/cps-global-lib/README.md

HTH

2015-02-06 21:01 GMT+01:00 Benjamin Muschko <[email protected]>:

> Hi,
>
> I was wondering what the technical limitations are for a workflow Groovy
> script, more specifically:
>
> 1) Is is possible to use classes like StringBuilder?
>
> Example:
>
> stage 'tryout'
> node {
>     useStringBuilder()
> }
>
> def useStringBuilder() {
>     echo "Before usage"
>     StringBuilder test = new StringBuilder()
>     echo "After usage"
> }
>
> If I use this method my in my flow.groovy script, the job never seems to
> print out "After usage". Instead I get the message: 
> "org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException:
> Scripts not permitted to use new java.lang.StringBuilder". Are "restricted"
> classes documented somewhere? Why is there a restriction?
>
> 2) Can you define your own classes within the Groovy script?
>
> stage 'tryout'
> node {
>     new HelloWorld().printMessage()
> }
>
> class HelloWorld {
>     def printMessage() {
>         echo "Hello World"
>     }
> }
>
> If I create an instance of a custom class, I get the following message: 
> "org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException:
> Scripts not permitted to use method groovy.lang.GroovyObject invokeMethod
> java.lang.String java.lang.Object".
>
> 3) Is there a way to reuse methods or classes across multiple jobs? How do
> you envision reusable code?
>
> In all of these cases, I'd like to consume an existing, checked-in Groovy
> script via "Groovy CPS DSL from SCM".
>
> Thanks,
>
> Ben
>
> --
> You received this message because you are subscribed to the Google Groups
> "Jenkins Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jenkinsci-users/2410ce55-ad9d-4d2b-b63c-6ebd633b85b5%40googlegroups.com
> <https://groups.google.com/d/msgid/jenkinsci-users/2410ce55-ad9d-4d2b-b63c-6ebd633b85b5%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Baptiste <Batmat> MATHUS - http://batmat.net
Sauvez un arbre,
Mangez un castor !

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/CANWgJS7tkKBd3PNq_VTj9xs9V47yRwquA7GuXoe_raQzcMtmyA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to