lony
lony

Reputation: 7799

Jenkins automatically approve script using configuration-as-code plugin for setup

I use configuration-as-code plugin to set up my Jenkins. The setup works and I see my job inside the Jenkins GUI.

If I now run it, I get the following error:

org.jenkinsci.plugins.scriptsecurity.scripts.UnapprovedUsageException: script not yet approved for use

I know if I manually approve the job, I can run it.

But how can I automatically approve these jobs?

Upvotes: 0

Views: 240

Answers (1)

Architect - Hitesh
Architect - Hitesh

Reputation: 1239

You can use Configuration-as-Code JCasC Plugin to automate the approving process.

  1. First manually approve the script using Jenkins UI.
  2. Approved Script will be added to ScriptApproval.xml file in Home directory
  3. Include XML file in JCasC YAML file as an unclassified section
  4. Now in order to automate the approval process you can use groovy script in initialization process that approves certain scripts and signatures by adding them directly into the security settings of jenikins

import org.jenkinsci.plugins.scriptsecurity.scripts.approvalProcess;
def approvalProcess= approvalProcess.get();
approvalProcess.approveSignature('YourScriptsSingature');
approvalProcess.save();

Upvotes: 0

Related Questions