Jenkins scripts run in the sandbox, by default the Groovy script does not have permissions for some operations.
When performing an operation without permissions issued RejectAccessException. So you have to execute your script, and then when the exception is thrown, go to:
http://yourHost/jenkins/scriptApproval/
And confirm the required permission:
