Consolidate the Downstream job emails

31 views
Skip to first unread message

sravan

unread,
Aug 23, 2019, 6:25:38 PM8/23/19
to Jenkins Users
Hi Guys,
I have 3 jobs which are running as pipeline

Job A
Downstream job is
Job B
Downstream job is
Job c

Currently it send 3 different emails for 3 different jobs

How can I get one email with all the job results 

Any help is appreciated

Thanks,
Sravan

sravan

unread,
Aug 26, 2019, 1:03:14 PM8/26/19
to Jenkins Users
Hi,
Could Someone help me with  that his please

Arnaud bourree

unread,
Aug 27, 2019, 1:44:12 AM8/27/19
to jenkins...@googlegroups.com
What do you expect in your consolidated email?
If job A calsl job B which calls job C, you can add email part parameter in job B and C.
If job C knows that job A and B run before, it could fetch information from previous job's artefacts on simply gets jobs result. 


--
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 jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/35a1b65e-f676-4723-a0b4-4dd6af66abc2%40googlegroups.com.

sravan

unread,
Aug 27, 2019, 1:48:33 AM8/27/19
to Jenkins Users
Job results of the three jobs in one email. Rather than it sending 3 different emails


On Monday, August 26, 2019 at 10:44:12 PM UTC-7, Arnaud wrote:
What do you expect in your consolidated email?
If job A calsl job B which calls job C, you can add email part parameter in job B and C.
If job C knows that job A and B run before, it could fetch information from previous job's artefacts on simply gets jobs result. 


Le lun. 26 août 2019 à 19:03, sravan <skkamb...@gmail.com> a écrit :
Hi,
Could Someone help me with  that his please

On Friday, August 23, 2019 at 3:25:38 PM UTC-7, sravan wrote:
Hi Guys,
I have 3 jobs which are running as pipeline

Job A
Downstream job is
Job B
Downstream job is
Job c

Currently it send 3 different emails for 3 different jobs

How can I get one email with all the job results 

Any help is appreciated

Thanks,
Sravan

--
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 jenkins...@googlegroups.com.

ankit kapoor

unread,
Aug 27, 2019, 2:07:00 AM8/27/19
to jenkins...@googlegroups.com
How to set different email addresses for different jobs ? any groovy script is required ? please help me on same ?

To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/0687d217-3207-4ace-b78c-e4d012b98a44%40googlegroups.com.

Dirk Heinrichs

unread,
Aug 27, 2019, 2:37:02 AM8/27/19
to jenkins...@googlegroups.com
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
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.
Reply all
Reply to author
Forward
0 new messages