Pipeline: Getting status of all parallel downstream jobs, mark build as unstable

386 views
Skip to first unread message

Dirk Heinrichs

unread,
May 2, 2018, 7:41:17 AM5/2/18
to jenkins...@googlegroups.com

Hi,

 

given the following simple pipeline script (just a POC):

 

stage('Testing') {

  def testSuites = env.TESTSUITES.split(',')

 

  def testJobs = [:]

  testSuites.each { suite ->

    testJobs[suite] = {

      build job: 'Executor', parameters: [string(name: 'TESTSUITE', value: suite)]

    }

  }

  parallel testJobs

}

 

How can I programmatically

  1. get the status of all downstream builds?
  2. set the current build to unstable?

 

What I currently get is that the pipeline job reports failure or success for all downstream jobs, but in the summary it just lists the first failed one. Since this should execute tests, I'd need to know which exact test has failed. It then also sets the overall status to failed, but I'd like to set it to unstable if at least one, but not all tests have failed.

 

How can I achieve this?

 

Thanks...

 

                Dirk

 

Dirk Heinrichs

Senior Systems Engineer, Delivery Pipeline

OpenText ™ Discovery | Recommind

Email: dhei...@opentext.com

Website: www.recommind.de

Recommind GmbH, Von-Liebig-Straße 1, 53359 Rheinbach

Vertretungsberechtigte Geschäftsführer John Marshall Doolittle, Gordon Davies, Roger Illing, Registergericht Amtsgericht Bonn, Registernummer HRB 10646

This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden

Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail sind nicht gestattet.

 

Victor Martinez

unread,
May 2, 2018, 10:16:50 AM5/2/18
to Jenkins Users
Hi,

Build step returns a RunWrapper object therefore you could save their status in another hash/array and then query whether any of those downstream builds are unstable if so then set the currentBuild as UNSTABLE, for instance based on your snippet:



import hudson.model.Result

stage('Testing') {

  def testSuites = ['a', 'b', 'c']

  def testJobs = [:]
  def status = [:]
  testSuites.each { suite ->
    testJobs[suite] = {
      status[suite] = build job: 'Executor1', parameters: [string(name: 'TESTSUITE', value: suite)], propagate: false
    }
  }

  parallel testJobs
  
  // set build status
  if (status.find { it.getValue().getResult().equals('UNSTABLE') }) {
     currentBuild.result = 'UNSTABLE'
  } else if (status.find { it.getValue().getResult().equals('FAILURE') }) {
     currentBuild.result = 'FAILURE'
  }
}


Further details:

My two cents

Dirk Heinrichs

unread,
May 2, 2018, 11:05:50 AM5/2/18
to jenkins...@googlegroups.com
From: jenkins...@googlegroups.com [mailto:jenkins...@googlegroups.com] On Behalf Of Victor Martinez

> Build step returns a RunWrapper object therefore you could save their status in another
> hash/array and then query whether any of those downstream builds are unstable if so
> then set the currentBuild as UNSTABLE, for instance based on your snippet:

Thanks a lot, will give it a try...

Bye...

Dirk
--
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 mailto:jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://urldefense.proofpoint.com/v2/url?u=https-3A__groups.google.com_d_msgid_jenkinsci-2Dusers_e8312e3b-2De9f1-2D4218-2D8dcd-2D7a06acb724a6-2540googlegroups.com-3Futm-5Fmedium-3Demail-26utm-5Fsource-3Dfooter&d=DwMFaQ&c=ZgVRmm3mf2P1-XDAyDsu4A&r=TsKycyisPP_6FVCeETRooIdY_8hdAsXoxwbvHso_TaI&m=_8THf_IhSFhhKugYED3ElQs4-HMZxOUhOSgIAjapNJ4&s=diQbxv6zyh3aW9oj8qdOjLJzT4bQgJ_r1nLl7WGM-vs&e=.
For more options, visit https://urldefense.proofpoint.com/v2/url?u=https-3A__groups.google.com_d_optout&d=DwMFaQ&c=ZgVRmm3mf2P1-XDAyDsu4A&r=TsKycyisPP_6FVCeETRooIdY_8hdAsXoxwbvHso_TaI&m=_8THf_IhSFhhKugYED3ElQs4-HMZxOUhOSgIAjapNJ4&s=GbaNSpHClmFhAkCGpPIvUADpe1H4xvmP-vG9HWL8WBA&e=.
Reply all
Reply to author
Forward
0 new messages