我想从另一个工作中触发詹金斯文件夹中的所有工作,为此我尝试编写詹金斯共享库并使用它。但是它会触发构建,然后失败并出现异常
我的共享库 runAllJobsInFolder.groovy:
def call(String foldername) {
def jobsList = []
def parallelJobs2Run = [:]
def project = Jenkins.instance.getItemByFullName(foldername)
def childItems = project.items
for (def i = 0; i < childItems.size(); i++) {
def childItem = childItems[i]
if (!childItem instanceof AbstractProject) continue;
if (childItem.fullName == foldername) continue;
jobsList.add(childItem.fullName)
}
for (int i = 0; i < jobsList.size(); i++) {
def job = jobsList[i]
echo "Going to parallel for job ${job}"
parallelJobs2Run["${job}"] = { ->
echo "Calling job ${job}"
build job: "${job}",
propagate: true
}
}
parallel parallelJobs2Run
}
========================================
在 Jenkins 工作中,我使用 runAllJobsInFolder "testfolder" 调用它
我想将触发作业的结果传播到主要作业
在工作日志中
Going to parallel for job testfolder/test1
[Pipeline] echo
Going to parallel for job testfolder/test2
[Pipeline] parallel
[Pipeline] [testfolder/test1] { (Branch: testfolder/test1)
[Pipeline] [testfolder/test2] { (Branch: testfolder/test2)
[Pipeline] [testfolder/test1] echo
[testfolder/test1] Calling job testfolder/test1
[Pipeline] [testfolder/test1] build (Building testFolder » test1)
[testfolder/test1] Scheduling project: testFolder » test1
[Pipeline] [testfolder/test2] echo
[testfolder/test2] Calling job testfolder/test2
[Pipeline] [testfolder/test2] build (Building testFolder » test2)
[testfolder/test2] Scheduling project: testFolder » test2
[Pipeline] [testfolder/test2] }
[testfolder/test2] Failed in branch testfolder/test2
[Pipeline] [testfolder/test1] }
[testfolder/test1] Failed in branch testfolder/test1
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] End of Pipeline
an exception which occurred:
in field com.cloudbees.groovy.cps.impl.BlockScopeEnv.locals
in object com.cloudbees.groovy.cps.impl.BlockScopeEnv@49674bfd
in field com.cloudbees.groovy.cps.impl.ProxyEnv.parent
in object com.cloudbees.groovy.cps.impl.LoopBlockScopeEnv@15e9217f
in field com.cloudbees.groovy.cps.impl.ProxyEnv.parent
in object com.cloudbees.groovy.cps.impl.BlockScopeEnv@6d430606
in field com.cloudbees.groovy.cps.impl.ProxyEnv.parent
in object com.cloudbees.groovy.cps.impl.BlockScopeEnv@19d10361
in field com.cloudbees.groovy.cps.impl.CpsClosureDef.capture
in object com.cloudbees.groovy.cps.impl.CpsClosureDef@ce48f2
in field com.cloudbees.groovy.cps.impl.CpsClosure.def
in object org.jenkinsci.plugins.workflow.cps.CpsClosure2@ce6143c
in field org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.closures
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@7e809250
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@7e809250
Caused: java.io.NotSerializableException: com.cloudbees.hudson.plugins.folder.Folder
at
org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:926)
at org.jboss.marshalling.river.BlockMarshaller.doWriteObject(BlockMarshaller.java:65)
在此处输入代码 在此处输入代码