Trying do compose menu with UnoChoice plugin, and add this menu to another job:
eg
// method hudson.model.ItemGroup getItem java.lang.String
//method jenkins.model.Jenkins createProject java.lang.Class java.lang.String
//method jenkins.model.Jenkins getItemByFullName java.lang.String java.lang.Class
//staticMethod jenkins.model.Jenkins get
//method hudson.model.Saveable save
//new org.biouno.unochoice.model.GroovyScript java.lang.String java.lang.String
import org.biouno.unochoice.model.GroovyScript
import org.biouno.unochoice.CascadeChoiceParameter
import hudson.model.FreeStyleProject
import jenkins.model.Jenkins
import com.cloudbees.hudson.plugins.folder.Folder
import hudson.model.ParametersDefinitionProperty
pipeline {
agent none
stages {
stage('Setup') {
steps {
script {
def jenkins = Jenkins.get()
// Folder and job setup
def folder = jenkins.getItemByFullName("MY_FOLDER", Folder.class) ?: jenkins.createProject(Folder, MY_FOLDER")
def job = folder.getItem("MY_JOB") ?: folder.createProject(FreeStyleProject, "MY_JOB")
// Scripts for choices
def scriptForFolder = new GroovyScript("return new File('/opt/delivery/folderFilesMap_update_lite.json').text.readLines()", "")
def scriptForFile = new GroovyScript("def jsonSlurper = new groovy.json.JsonSlurper(); def data = jsonSlurper.parse(new File('/opt/delivery/folderFilesMap_update_lite.json').text); return data[params['SELECTED_FOLDER']];", "")
// Parameters
def folderParam = new CascadeChoiceParameter(
"SELECTED_FOLDER",
"Select a folder",
"PT_SINGLE_SELECT",
scriptForFolder,
"",
false, // filterable
5, // maxShownItems
"", // fallbackScript
"NONE",// filterLength
"ALL" // enableDependencies
)
def fileParam = new CascadeChoiceParameter(
"SELECTED_FILE",
"Select a file",
"PT_SINGLE_SELECT",
scriptForFile,
"SELECTED_FOLDER",
false,
5,
"",
"NONE",
"ALL"
)
job.addProperty(new ParametersDefinitionProperty([folderParam, fileParam]))
job.save()
}
}
}
}
}
But got error - How to avoid it?
Also: org.jenkinsci.plugins.workflow.actions.ErrorAction$ErrorId: 231cf148-b345-48e6-8c7c-6663547e0eff
java.lang.SecurityException: Unable to find constructor: new org.biouno.unochoice.CascadeChoiceParameter java.lang.String java.lang.String java.lang.String org.biouno.unochoice.model.GroovyScript java.lang.String java.lang.Boolean java.lang.Integer java.lang.String java.lang.String java.lang.String
at org.kohsuke.groovy.sandbox.impl.GroovyCallSiteSelector.findConstructor(GroovyCallSiteSelector.java:47)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedConstructor(Checker.java:223)
at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.constructorCall(SandboxInvoker.java:21)
at org.jenkinsci.plugins.workflow.cps.LoggingInvoker.constructorCall(LoggingInvoker.java:110)
at WorkflowScript.run(WorkflowScript:32)
at ___cps.transform___(Native Method)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:100)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:85)
at jdk.internal.reflect.GeneratedMethodAccessor1091.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
at com.cloudbees.groovy.cps.Next.step(Next.java:83)
at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:152)
at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:146)
at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:136)
at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:275)
at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:146)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:51)
at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:187)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:423)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:331)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:295)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:97)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:139)
at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:68)
at jenkins.util.ErrorLoggingExecutorService.lambda$wrap$0(ErrorLoggingExecutorService.java:51)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:840)