0
votes

I have something really weird happening.

I use jenkins scripted pipeline to send an email with email ext plugin and template groovy-html.template. The email is properly sent if the changeset is empty or if the build result is failure, but if the build result is in (SUCCESS, UNSTABLE) and the changeset not empty, i never get the email... I looked into all jenkins logs and did not find any error that could explain this behavior. The issue is also happening with email template jelly html or groovy text.

Any idea why i'm getting this behaviour?

Here is my codesnipped:

emailext(
        subject: 'Deployment',
        body: '${SCRIPT, template="groovy-html.template"}',
        to: '[email protected]')

And here is the complete pipeline.

1
Can you show us the code section from emailext?RNoB
the template is the default groovy-html one, github.com/jenkinsci/email-ext-plugin/blob/master/src/main/…Maxime Lem
and here's the pipeline: gist.github.com/emexelem/f84aabb2b4e9bbe2f949e045917d210b If i uncomment the line currentBuild.result = 'FAILURE', i get the email, if i leave it commented, i do not.Maxime Lem
I don't think that there is a Problem with the html-template. Can you give it a try without the brackets, because you are using scripted pipeline: emailext subject: 'Deployment', body: '${SCRIPT, template="groovy-html.template"}', to: '[email protected]'RNoB
i tried without the braces, it does not change anything. Though I found that the email is properly received if i switch to my personal email address, which is on gmail. Looks like the issue is with my professional email. For some reason the email seems to be caught by anti-spam or something when build is successful and has a changeset... I also found that the html styles are not properly rendered in gmail. I fixed this by including the style section under a <!DOCTYPE html><html><head> in the email template.Maxime Lem

1 Answers

0
votes

Would you like to try to use a declarative pipeline?

change this section

node('master') {
    checkout(scm: [$class: 'GitSCM', 
        branches: [[name: "*/develop"]],
        extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'repo1']], 
        userRemoteConfigs: [[credentialsId: 'bitbucket.jenkins', 
        url: 'urlToRepo.git']]],
        changelog: true, poll: true)

    showChangeLogs()

    //currentBuild.result = 'FAILURE'

    emailext(
        subject: 'Deployment',
        body: '${SCRIPT, template="groovy-html.template"}',
        to: '[email protected]')
}

by this one

pipeline {
    agent any
    stages {
        stage('master') {
            steps {
                script {
                    checkout(scm: [$class: 'GitSCM', 
                        branches: [[name: "*/develop"]],
                        extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'repo1']], 
                        userRemoteConfigs: [[credentialsId: 'bitbucket.jenkins', 
                        url: 'urlToRepo.git']]],
                        changelog: true, poll: true)

                    showChangeLogs()

                    //currentBuild.result = 'FAILURE'

                }
            }
        }
    }
    post { 
        always { 
            emailext(
                subject: 'Deployment',
                body: '${SCRIPT, template="groovy-html.template"}',
                to: '[email protected]')
        }
    }
}