collect the result from pipeline triggered downstream jobs

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

collect the result from pipeline triggered downstream jobs

treneva
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

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAG6hjyWEZvKBJNyFj1xUt7Zb%3Deuz%2Bc5PMGVDyPH4-srR2k3PoQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: collect the result from pipeline triggered downstream jobs

gustaf.lundh
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

On Tuesday, October 16, 2018 at 3:00:44 PM UTC+2, Vassilena Treneva wrote:
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: <a href="https://groups.google.com/forum/#!topic/jenkinsci-dev/nNvy6YLgP58" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/forum/#!topic/jenkinsci-dev/nNvy6YLgP58&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/forum/#!topic/jenkinsci-dev/nNvy6YLgP58&#39;;return true;">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: <a href="https://jenkins.io/doc/pipeline/steps/pipeline-build-step/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fjenkins.io%2Fdoc%2Fpipeline%2Fsteps%2Fpipeline-build-step%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEWT0X8m7x3_MTNPkNTTn-4lGctHw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fjenkins.io%2Fdoc%2Fpipeline%2Fsteps%2Fpipeline-build-step%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEWT0X8m7x3_MTNPkNTTn-4lGctHw&#39;;return true;">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

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/bbe36f93-a18c-45c5-b887-ed67c61c526d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.