Am Freitag, den 23.08.2019, 15:24 -0700 schrieb sravan:

How can I get one email with all the job results

If job A was a Multijob, you can do this using Extended Email plugin together 
with a pre-send script which traverses the sub jobs to get their results and 
prepare the email body.

Sample script:

// Scan all downstream jobs of a MultiJob and prepare the final email text

import hudson.model.*
import com.tikal.jenkins.plugins.multijob.*

// Get some environment vars
def url = build.envVars['JENKINS_URL'].replaceAll('/*$', '')

// Set summary header
def result = build.getResult()
def h2 = ''
switch (result) {
  case 'ABORTED':
    h2 = '''<h2>Your job was aborted</h2>
<h3>Aborts usually have one of two reasons:</h3>
<ol>
  <li>Manual abort</li>
  <li>Timeout</li>
</ol>'''
    break
  case 'FAILURE':
    h2 = '<h2>Your job has failed</h2>'
    break
  case 'SUCCESS':
    h2 = '<h2>Your job was successfull</h2>'
    break
}
def header = h2
header += '<h3>Job status summary</h3>'
header += '<a href="' + url + '/' + build.getUrl() + '">' + 
build.getProject().getFullName() + ' #' + build.getNumber() + ': ' + result + 
'</a>'
header += '<ul style="list-style: none; ">'

// Initialize data structure
def data = [
  subJobs: 0,
  failed: false,
  sum: header,
  url: url
]

// Recursive method to create status summary for all sub jobs
// Params:
//   - job: a multijob object
//   - a data structure as defined above
// Returns:
//   - A modified data structure with updated sum and failed fields
Map collectResults(build, data) {
  // Iterate over sub builds
  build.getSubBuilds().each { subBuild ->
    def theBuild = subBuild.getBuild()
    data['subJobs'] += 1
    // Get sub build's metadata
    def subName = theBuild.getProject().getFullName()
    def subNumber = subBuild.getBuildNumber()
    def subUrl = data['url'] + '/' + subBuild.getUrl()
    def result = subBuild.getResult()
    def failed = (result == "FAILURE")

    // Update overall status
    data['failed'] = data['failed'] || failed

    // Append to summary
    data['sum'] += '<li><a href="' + subUrl + '">' + subName + ' #' + subNumber 
+ ': ' + result + '</a></li>'

    // Recurse, if current sub build is a MultiJobBuild itself
    if (theBuild instanceof com.tikal.jenkins.plugins.multijob.MultiJobBuild) {
      data['sum'] += '<li><ul style="list-style: none; ">'
      data = collectResults(theBuild, data)
      data['sum'] += '</ul></li>'
    }
  }
  return data
}

try {
  // Collect results of all sub jobs
  data = collectResults(build, data)

  def summary = data['sum']
  summary += '</ul>'
  summary += '<h3>Additional information</h3>'
  summary += '<a href="' + build.envVars['JOB_URL'] + '">Main job page</a><br>'

  // Set message body
  msg.setContent(summary, 'text/html')
}
catch(Exception e) {
  log("ERROR: ${e.message}")
  log("ERROR: Failed status report aggregation")
}


HTH...

Dirk

--

Dirk Heinrichs
Senior Systems Engineer, Delivery Pipeline
OpenText ™ Discovery | Recommind
Phone: +49 2226 15966 18
Email: [email protected]<mailto:[email protected]>
Website: www.recommind.de
Recommind GmbH, Von-Liebig-Straße 1, 53359 Rheinbach
Vertretungsberechtigte Geschäftsführer Gordon Davies, Madhu Ranganathan, 
Christian Waida, 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.

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/e3d2c822303ea51d82f98cb7eb9452f38912e98d.camel%40opentext.com.

Reply via email to