-
Bug
-
Resolution: Not A Defect
-
Major
In all my jobs I'm making use of the dynamicparameter plugin to have dynamisch parameters. For example to provide a list of existing environments to the user. If a new env is added, the dropdown is automatically updated. This is just a small example.
At the moment I'm refactoring all my existing jobs into pipeline jobs, this allows me to have the job config under version control. I would also like to add the parameters into my jenkinsfile.
At the moment I have the following setup :
def cmd = System.getenv()['HOME']+"/scripts/bin/listExistingEnvironments.sh -f cfs"; def envs = cmd.execute().text.replaceAll(",", "\n"); properties([ buildDiscarder( logRotator( artifactDaysToKeepStr: '1', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '30' ) ), disableConcurrentBuilds(), parameters([ choice(choices: envs, description: 'Please provide the environment to deploy to (e.g: uat)', name: 'Environment') ]), [$class: 'ThrottleJobProperty', categories: [], limitOneJobWithMatchingParams: false, maxConcurrentPerNode: 0, maxConcurrentTotal: 0, paramsToUseForLimit: '', throttleEnabled: false, throttleOption: 'project'], pipelineTriggers([pollSCM('H/15 * * * *')]) ])
This will populate dynamically the static dropdown, during the build of the job. Which is too late, I need to values before the build start, I need them just before selecting the parameters.
That is what the dynamicparameter plugin provides us.
I tryed to use it in the pipeline definition like so
package com.seitenbau.jenkins.plugins.dynamicparameter; import com.seitenbau.jenkins.plugins.dynamicparameter.*; import org.jenkinsci.plugins.scriptler.config.Script; import com.seitenbau.jenkins.plugins.dynamicparameter.util.JenkinsUtils; def cmd = System.getenv()['HOME']+"/scripts/bin/listExistingEnvironments.sh -f cfs"; def envs = cmd.execute().text.replaceAll(",", "\n"); properties([ buildDiscarder( logRotator( artifactDaysToKeepStr: '1', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '30' ) ), disableConcurrentBuilds(), parameters([ new com.seitenbau.jenkins.plugins.dynamicparameter.StringParameterDefinition(name: 'test', script: 'println "lala"', description:'ffff', uuid: '821390120219201', remote: false, classPath: '') ]), [$class: 'ThrottleJobProperty', categories: [], limitOneJobWithMatchingParams: false, maxConcurrentPerNode: 0, maxConcurrentTotal: 0, paramsToUseForLimit: '', throttleEnabled: false, throttleOption: 'project'], pipelineTriggers([pollSCM('H/15 * * * *')]) ])
But that resulted in the follow error
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: unclassified new com.seitenbau.jenkins.plugins.dynamicparameter.StringParameterDefinition java.util.LinkedHashMap at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onNewInstance(SandboxInterceptor.java:126) at org.kohsuke.groovy.sandbox.impl.Checker$3.call(Checker.java:191) at org.kohsuke.groovy.sandbox.impl.Checker.checkedConstructor(Checker.java:188) at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.constructorCall(SandboxInvoker.java:20) at com.seitenbau.jenkins.plugins.dynamicparameter.WorkflowScript.run(WorkflowScript:20) at ___cps.transform___(Native Method) at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:96) at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:82)