Highway of Life
Highway of Life

Reputation: 24301

How to programmatically approve Jenkins System Groovy Script

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?

Upvotes: 4

Views: 9114

Answers (1)

yun abs
yun abs

Reputation: 111

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()

Upvotes: 10

Related Questions