尝试运行我的詹金斯工作时出现以下错误。任何帮助将不胜感激
java.lang.IllegalArgumentException:预期的命名参数但得到了 [org.jenkinsci.plugins.workflow.cps.CpsClosure2@33c7c4a6, org.jenkinsci.plugins.workflow.cps.CpsClosure2@79505a8c, org.jenkinsci.plugins.workflow.cps.CpsClosure2@6a96df3, org.jenkinsci.plugins.workflow.cps.CpsClosure2@1a0cb771, org.jenkinsci.plugins.workflow.cps.CpsClosure2@17e3a262] org.jenkinsci.plugins.workflow.cps.DSL.singleParam(DSL.java:606)在 org.jenkinsci.plugins.workflow.cps.DSL.parseArgs(DSL.java:594)在 org.jenkinsci.plugins.workflow.cps.DSL.parseArgs(DSL.java:534)在 org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:219)位于 org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:178)在 org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122) 在sun.reflect.GeneratedMethodAccessor102.invoke(未知来源)
我的代码是:
node("dvsacvsmgmt") {
stage("Build") {
def buildJobs = []
for (BACKEND_SERVICE in BACKEND_SERVICES) {
SVC = BACKEND_SERVICE.replaceAll('-','_')
switch (BRANCH_SVC) {
case ["develop","master"]:
def buildJob = {
build "${ROOT_FOLDER}/2_Build/Backend/${SVC}/job_build_backend_" + BRANCH_SVC + "_" + SVC +".groovy"
}
buildJobs.add(buildJob)
break
default:
def buildJob = {
build "job_${SVC}": "${ROOT_FOLDER}/2_Build/Backend/${SVC}/job_build_backend_" + BRANCH_SVC + "_" + SVC +".groovy",
parameters: [gitParameter(name: "BRANCH", value: BRANCH_SVC)]
}
buildJobs.add(buildJob)
break
}
}
parallel(buildJobs)
}
}
注意:我的变量定义在顶部
BRANCH,BRANCH_SVC,ROOT_FOLDER,BACKEND_SERVICES
答案 0 :(得分:0)
您会看到此异常,因为示例中的buildJobs
是闭包列表,而应该是一个映射。将后端服务名称用作您传递给parallel()
方法的映射的键是很有意义的。考虑对您的代码进行以下更改:
node("dvsacvsmgmt") {
stage("Build") {
def buildJobs = [:]
for (BACKEND_SERVICE in BACKEND_SERVICES) {
SVC = BACKEND_SERVICE.replaceAll('-','_')
switch (BRANCH_SVC) {
case ["develop","master"]:
def buildJob = {
build "${ROOT_FOLDER}/2_Build/Backend/${SVC}/job_build_backend_" + BRANCH_SVC + "_" + SVC +".groovy"
}
buildJobs.put(BACKEND_SERVICE, buildJob)
break
default:
def buildJob = {
build "job_${SVC}": "${ROOT_FOLDER}/2_Build/Backend/${SVC}/job_build_backend_" + BRANCH_SVC + "_" + SVC +".groovy",
parameters: [gitParameter(name: "BRANCH", value: BRANCH_SVC)]
}
buildJobs.put(BACKEND_SERVICE, buildJob)
break
}
}
parallel(buildJobs)
}
}
它调用
buildJobs.put(BACKEND_SERVICE, buildJob)
代替
buildJobs.add(buildJob)
创建一个映射,该映射在parallel
方法调用中被视为命名参数。