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,