Handling In-process Script Approval

1,250 views
Skip to first unread message

jacek.sni...@agilone.com

unread,
Feb 7, 2017, 2:29:54 PM2/7/17
to job-dsl-plugin
My jobs use parameters created by Groovy scripts via Extended Choice parameters and Active Choices Parameter.
These scripts change, as they return list of available builds.

As a result, every time I regenerate the jobs with JobDSL, I have to manually approve a bunch of Groovy scripts.
For now I just have a Groovy script job that is hooked up as a post build step and it approves all scripts but this is not maintainable for me in the long run.

1. Active Choices Parameter has a 'Run in sandbox' mode but JobDSL doesn't provide a way to enable it. I could resort to 'config' node but would prefer something less messy.
2. Extended Choice doesn't even provide that parameter, so what can I do in that case?

Thanks for the help.

jacek.sni...@agilone.com

unread,
Feb 8, 2017, 4:00:35 PM2/8/17
to job-dsl-plugin
Solved.
I moved the Groovy script to Scriptler and converted all jobs to use Active Parameter plugin with this code:

parameters {
        activeChoiceParam('branchToBuild') {
          description('Select a release branch to build from.')
          choiceType('SINGLE_SELECT')
          scriptlerScript("getBranches.groovy") {
            parameter("repoName", "myRepo")
          }
        }
      }

Stefano Salvatori

unread,
May 22, 2017, 3:58:42 AM5/22/17
to job-dsl-plugin
Hi

Do you have the code for this "automatic" approval ? i'm trying to do the same using for some job's seeders and also some pipelines

S.

jacek.sni...@agilone.com

unread,
May 22, 2017, 1:24:40 PM5/22/17
to job-dsl-plugin
Hi, Stefano. Sure, this is the Groovy step I used. You need to put it in the 'Execute system Groovy script' build step:

import jenkins.model.Jenkins

def scriptApproval = Jenkins.instance.getExtensionList('org.jenkinsci.plugins.scriptsecurity.scripts.ScriptApproval')[0]
def hashesToApprove = scriptApproval.pendingScripts.collect{ it.getHash() }
hashesToApprove.each { 
  scriptApproval.approveScript(it)
}


Reply all
Reply to author
Forward
0 new messages