Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-35367

EMail-Ext Extended Pipeline Support - Templates

    XMLWordPrintable

    Details

    • Similar Issues:

      Attachments

        Issue Links

          Activity

          Hide
          nikk699 Faheem Nadeem added a comment -

          Is their an example on how to use tokens?

          Show
          nikk699 Faheem Nadeem added a comment - Is their an example on how to use tokens?
          Hide
          stegeman niet niet1 added a comment -

          Thanks to the developer for making the support for the template

          Faheem Nadeem, see attachement sendMail.groovy for an example with template and tokens

          Show
          stegeman niet niet1 added a comment - Thanks to the developer for making the support for the template Faheem Nadeem , see attachement sendMail.groovy for an example with template and tokens
          Hide
          aheritier Arnaud Héritier added a comment -

          Hi David van Laatum

          It could be interesting to add sendMail.groovy in the sample directory and a link in the plugin documentation

          WDYT?

          Show
          aheritier Arnaud Héritier added a comment - Hi David van Laatum It could be interesting to add sendMail.groovy in the sample directory and a link in the plugin documentation WDYT?
          Hide
          davidvanlaatum David van Laatum added a comment -

          not exactly the best of examples eg the recipient providers could be passed directly to emailext rather than going through emailextrecipients. It also replicates much of the features of emailext

          	// Append Culprits when the build is not successfull
          	if (currentBuild.result != "SUCCESS") {
          		to << emailextrecipients([[$class: 'CulpritsRecipientProvider']])
          	}
          

          is redundant as CulpritsRecipientProvider only adds culprits to the list if the build failed.
          It also doesn't handle the body throwing an exception
          In theory this is better (untested)

          def call(body) {
              // evaluate the body block, and collect configuration into the object
              def config = [:]
              body.resolveStrategy = Closure.DELEGATE_FIRST
              body.delegate = config
              try {
                  body()
              } catch(e) {
                  currentBuild.result = "FAILURE";
                  throw e;
              } finally {
                  def subject = config.subject ? config.subject : "${env.JOB_NAME} - Build #${env.BUILD_NUMBER} - ${currentBuild.result}!"
                  def content = '${JELLY_SCRIPT,template="static-analysis"}'
                  // Attach buildlog when the build is not successfull
                  def attachLog = (config.attachLog != null) ? config.attachLog : (currentBuild.result != "SUCCESS")
                  // Send email
                  emailext(body: content, mimeType: 'text/html',
                          replyTo: '$DEFAULT_REPLYTO', subject: subject,
                          to: config.emailRecipients, attachLog: attachLog, recipientProviders: [[$class: 'CulpritsRecipientProvider'], [$class: 'RequesterRecipientProvider']])
              }
          }
          
          Show
          davidvanlaatum David van Laatum added a comment - not exactly the best of examples eg the recipient providers could be passed directly to emailext rather than going through emailextrecipients. It also replicates much of the features of emailext // Append Culprits when the build is not successfull if (currentBuild.result != "SUCCESS" ) { to << emailextrecipients([[$class: 'CulpritsRecipientProvider' ]]) } is redundant as CulpritsRecipientProvider only adds culprits to the list if the build failed. It also doesn't handle the body throwing an exception In theory this is better (untested) def call(body) { // evaluate the body block, and collect configuration into the object def config = [:] body.resolveStrategy = Closure.DELEGATE_FIRST body.delegate = config try { body() } catch (e) { currentBuild.result = "FAILURE" ; throw e; } finally { def subject = config.subject ? config.subject : "${env.JOB_NAME} - Build #${env.BUILD_NUMBER} - ${currentBuild.result}!" def content = '${JELLY_SCRIPT,template= " static -analysis" }' // Attach buildlog when the build is not successfull def attachLog = (config.attachLog != null ) ? config.attachLog : (currentBuild.result != "SUCCESS" ) // Send email emailext(body: content, mimeType: 'text/html' , replyTo: '$DEFAULT_REPLYTO' , subject: subject, to: config.emailRecipients, attachLog: attachLog, recipientProviders: [[$class: 'CulpritsRecipientProvider' ], [$class: 'RequesterRecipientProvider' ]]) } }
          Hide
          aheritier Arnaud Héritier added a comment -
          Show
          aheritier Arnaud Héritier added a comment - thanks David van Laatum

            People

            • Assignee:
              davidvanlaatum David van Laatum
              Reporter:
              davidvanlaatum David van Laatum
            • Votes:
              14 Vote for this issue
              Watchers:
              25 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: