Email from Jenkins Pipelines

85 views
Skip to first unread message

Grace P

unread,
Sep 20, 2019, 3:06:13 PM9/20/19
to Jenkins Users
hi all , 
I want to be able to send mails from a Pipeline Job on Jenkins... here what I done and do not work 
--- 
installed the Email Extension Plugin (2.66) for Jenkins (2.176.3) to use in Pipelines and I'm trying the example on: https://medium.com/@gustavo.guss/jenkins-sending-email-on-post-build-938b236545d2
pipeline {
    environment {
        //This variable need be tested as string
        doError = '1'
    }

    agent any

    stages {
        stage('Error') {
            when {
                expression { doError == '1' }
            }
            steps {
                echo "Failure"
                error "failure test. It's work"
            }
        }

        stage('Success') {
            when {
                expression { doError == '0' }
            }
            steps {
                echo "ok"
            }
        }
    }
    post {
        always {
            echo 'I will always say Hello again!'

            emailext body: "${currentBuild.currentResult}: Job ${env.JOB_NAME} build ${env.BUILD_NUMBER}\n More info at: ${env.BUILD_URL}",
                recipientProviders: [[$class: 'DevelopersRecipientProvider'], [$class: 'RequesterRecipientProvider']],
                subject: "Jenkins Build ${currentBuild.currentResult}: Job ${env.JOB_NAME}"

        }
    }
}

But I have the following error :

Error when executing always post condition: java.lang.NoSuchMethodError: No such DSL method 'emailext' found among steps [VersionNumber, acceptGitLabMR, addGitLabMRComment, archive, bat, build, catchError, checkout, deleteDir, dir, dockerFingerprintFrom, dockerFingerprintRun, echo, envVarsForTool, error, fileExists, findFiles, getContext, ...

Also I cannot configure the plugin itself and I do not know how to activate it, I restarted Jenkins, the system and did not work , the pipeline syntax editor does not recognize the plugin, any suggestions ?

I posted the same question on stackoverflow ... 

https://stackoverflow.com/questions/58031972/email-plugin-on-jenkins-pipelines 

Also I try with an simple pipeline job that should send a mail (I guess it is with the default Mail plugin ), I configured on Manage jenkins -> Configure System with port 465 and the appropriated SMTP server , when I test the configuration by sending an e-mail  , it sends and I can see the test mail on my inbox , but from the pipeline job , it fails: 


```

node {

stage("test") {
def message = "hello there!"

mail bcc: '', body: message, cc: '', from: 'a...@mycom.com', replyTo: 'jenki...@mycom.com', subject: "Develop: build generated ", to:'gr...@mycom.com'
}

}

```
Error:

```
java.net.SocketException: Connection closed by remote host
at sun.security.ssl.SSLSocketImpl.checkWrite(Unknown Source)
at sun.security.ssl.AppOutputStream.write(Unknown Source)
at com.sun.mail.util.TraceOutputStream.write(TraceOutputStream.java:114)
at java.io.BufferedOutputStream.flushBuffer(Unknown Source)
at java.io.BufferedOutputStream.flush(Unknown Source)
at com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:2104)
Caused: javax.mail.MessagingException: Can't send command to SMTP host;
  nested exception is:
java.net.SocketException: Connection closed by remote host
at com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:2106)
at com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:2093)
at com.sun.mail.smtp.SMTPTransport.close(SMTPTransport.java:1184)
```
Any suggestion how to fix it?


thanks,

Reply all
Reply to author
Forward
0 new messages