4

Jenkins Job DSL introduced Script Security in 1.6, this gives some builds the following error:

ERROR: Build step failed with exception
org.jenkinsci.plugins.scriptsecurity.scripts.UnapprovedUsageException: script not yet approved for use

We run Jenkins masters entirely through configuration using plugins.txt and a set of Groovy scripts to configure Jenkins, and do not allow any configuration to be done through the UI, so we also disable the ability to login as an admin.

How can we programmatically pre-approve scripts through the Jenkins groovy configuration?

Highway of Life
  • 22,803
  • 16
  • 52
  • 80
  • you can do it from the Jenkinsfile itself like so https://stackoverflow.com/questions/47925058/how-to-approve-script-snippets-from-a-jenkinsfile-via-the-groovy-script-consolev – rohit thomas Jun 22 '18 at 03:03
  • 4
    Possible duplicate of [How to approve script snippets from a jenkinsfile via the groovy script console?](https://stackoverflow.com/questions/47925058/how-to-approve-script-snippets-from-a-jenkinsfile-via-the-groovy-script-console) – Szymon Stepniak Jun 22 '18 at 07:51

1 Answers1

10

Below is for approving two method with groovy on jenkins.

def scriptApproval = org.jenkinsci.plugins.scriptsecurity.scripts.ScriptApproval.get()

String[] signs = [
    "method org.jenkinsci.plugins.workflow.steps.FlowInterruptedException getCauses",
    "method org.jenkinsci.plugins.workflow.support.steps.input.Rejection getUser"
    ]

for( String sign : signs ) {
    scriptApproval.approveSignature(sign)
}

scriptApproval.save()
pabrantes
  • 2,161
  • 1
  • 28
  • 34
yun abs
  • 111
  • 1
  • 4