collect the result from pipeline triggered downstream jobs

669 views
Skip to first unread message

Vassilena Treneva

unread,
Oct 16, 2018, 9:00:44 AM10/16/18
to jenkins...@googlegroups.com
Hey,

I have been trying different ways to collect the result from pipeline triggered downstream jobs without any success. Any idea how to do it?

Apprioach #1 - Mapping the build data trough Cause.UpstreamCause (as suggested here: https://groups.google.com/forum/#!topic/jenkinsci-dev/nNvy6YLgP58):

pipelineIntegrationJobs.each {
i -> jobs["${nirvanaMajor}.${nirvanaMinor}_${i}"] = {
build (job: "${nirvanaMajor}.${nirvanaMinor}_${i}", 
parameters: [
string(name: 'branch', value: "${svnBranch}", description: 'svn repository url'), 
string(name: 'buildmajor', value: '10', description: 'release major identifier'),
string(name: 'buildminor', value: '4', description: 'release minor identifier'),
string(name: 'fix', value: "${env.fix}", description: 'fix level'), 
string(name: 'buildnumber', value: "${env.buildNumber}", description: 'artifacts build number'), 
string(name: 'revision', value: "${env.buildNumber}", description: 'checkout revision'),
string(name: 'joblabel', value: "${pipelineName}", description: "optional job description")
], quietPeriod: 0, propagate: false, wait: true).result
def upstreamJob = Jenkins.instance.getItem("${nirvanaMajor}.${nirvanaMinor}_${env.JOB_NAME}")
def job = Jenkins.instance.getItem("${nirvanaMajor}.${nirvanaMinor}_${i}")
job.builds.each { Run build ->
if (build.result != null) {
Cause.UpstreamCause cause = build.getCause(Cause.UpstreamCause.class)
if (cause.pointsTo(upstreamJob)) {
println("------------>" + build.number)
}
}
}
}
}

This results in a NPE:
05:34:41 Finished
[Pipeline] script
[Pipeline] {
[Pipeline] echo
05:34:41 ------------------------------------
[Pipeline] echo
05:34:41 Job Status Summary:
[Pipeline] echo
05:34:41 10.4:null
[Pipeline] echo
05:34:41 ------------------------------------
[Pipeline] echo
05:34:41 ------------------------------------
[Pipeline] echo
05:34:41 Test Results Summary:
[Pipeline] echo
05:34:41 ------------------------------------
[Pipeline] }
[Pipeline] // script
[Pipeline] echo
05:34:41 Failure
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // timestamps
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
[BFA] Scanning build for known causes...
[BFA] No failure causes found
[BFA] Done. 0s
java.lang.NullPointerException
at hudson.model.Cause$UpstreamCause.pointsTo(Cause.java:262)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:47)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:157)
at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:133)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:155)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:159)
at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
at pipelineBuilder.call(/FS/fslocal/jenkinsWorkspace/jobs/10.4_release_pipeline/builds/84/libs/templates/vars/pipelineBuilder.groovy:182)
at com.cloudbees.groovy.cps.CpsDefaultGroovyMethods.each(CpsDefaultGroovyMethods:2030)
at com.cloudbees.groovy.cps.CpsDefaultGroovyMethods.each(CpsDefaultGroovyMethods:2015)
at com.cloudbees.groovy.cps.CpsDefaultGroovyMethods.each(CpsDefaultGroovyMethods:2056)
at pipelineBuilder.call(/FS/fslocal/jenkinsWorkspace/jobs/10.4_release_pipeline/builds/84/libs/templates/vars/pipelineBuilder.groovy:179)
at ___cps.transform___(Native Method)

Approach #2 - Using the .result property of the build job (as suggested in the official documentation here: https://jenkins.io/doc/pipeline/steps/pipeline-build-step/):

pipelineIntegrationJobs.each {
i -> jobs["${nirvanaMajor}.${nirvanaMinor}_${i}"] = {
childJob = build (job: "${nirvanaMajor}.${nirvanaMinor}_${i}", 
parameters: [
string(name: 'branch', value: "${svnBranch}", description: 'svn repository url'), 
string(name: 'buildmajor', value: '10', description: 'release major identifier'),
string(name: 'buildminor', value: '4', description: 'release minor identifier'),
string(name: 'fix', value: "${env.fix}", description: 'fix level'), 
string(name: 'buildnumber', value: "${env.buildNumber}", description: 'artifacts build number'), 
string(name: 'revision', value: "${env.buildNumber}", description: 'checkout revision'),
string(name: 'joblabel', value: "${pipelineName}", description: "optional job description")
], quietPeriod: 0, propagate: false, wait: true).result
}
childJobName = "${nirvanaMajor}.${nirvanaMinor}_${i}"
jobStateResults.put(childJobName, childJob)
}

In post section:
script {
println "------------------------------------"
println "Job Status Summary:"
jobStateResults.each{ k, v -> println "${k}:${v}" }
println "------------------------------------"
}

This yields null:

17:56:37 [10.4_test_admin_api_win] null
[Pipeline] [10.4_test_admin_api_win] }
[Pipeline] [10.4_test_admin_tool_win] echo
18:04:25 [10.4_test_admin_tool_win] null
[Pipeline] [10.4_test_admin_tool_win] }
[Pipeline] [10.4_test_cluster_tool_win] echo
18:17:44 [10.4_test_cluster_tool_win] null
[Pipeline] [10.4_test_cluster_tool_win] }
[Pipeline] [10.4_test_jms_linux] echo
18:22:33 [10.4_test_jms_linux] null
[Pipeline] [10.4_test_jms_linux] }
[Pipeline] [10.4_test_client_system_linux] echo
18:26:41 [10.4_test_client_system_linux] null
[Pipeline] [10.4_test_client_system_linux] }
[Pipeline] [10.4_test_jms_win] echo
18:39:40 [10.4_test_jms_win] null
[Pipeline] [10.4_test_jms_win] }
[Pipeline] [10.4_test_client_system_win] echo
18:47:20 [10.4_test_client_system_win

gustaf...@axis.com

unread,
Nov 6, 2018, 8:11:06 AM11/6/18
to Jenkins Users
Perhaps https://wiki.jenkins.io/display/JENKINS/Downstream+Build+Cache+Plugin can help you?

It is used by https://wiki.jenkins.io/display/JENKINS/Yet+Another+Build+Visualizer+Plugin to visualize how builds are triggered.

Essentially, it allows you to easily fetch a list triggered downstream builds:

Set<Run> downstreamBuilds = BuildCache.getCache().getDownstreamBuilds(sourceBuild)

/Gustaf
Reply all
Reply to author
Forward
0 new messages