Setting Up Email Notifications for Jenkins Stages: Pipeline Script

2.9k views Asked by At

I am looking to send out an email on failure and/or list of all of the stages and their status. I have wrapped my code in a try{} and am catching any failures. On my Console output it says that the email was sent to the appropriate email but I am not receiving it... Under my Configuration on Jenkins I have set up my Jenkins Location, E-mail Notification and Extended E-mail Notifications set up. I have confirmed that the E-mail Notifications work properly and added the same credentials to the Extended E-mail Notifications. Here is my console out put:

Running on Dobby in D:Pipelinefolder
[Pipeline] {
[Pipeline] emailext
Sending email to: [email protected]
[Pipeline] stage
[Pipeline] { (Checkout)
[Pipeline] checkout

and

Results (nunit3) saved as TestResult.xml
[Pipeline] }
[Pipeline] // stage
[Pipeline] emailext
Sending email to: [email protected]
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline

Please view my code below:

node('Dobby') {
try {
    notifyBuild('STARTED')

stage('Checkout') {
checkout([$class: 'SubversionSCM',
    additionalCredentials: [], 
    excludedCommitMessages: '', 
    excludedRegions: '', 
    excludedRevprop: '', 
    excludedUsers: 'buildbot', 
    filterChangelog: false, 
    ignoreDirPropChanges: false, 
    includedRegions: '', 
    locations: [[credentialsId: 'aPpr0pR1at3.CrDEnt1Al5.83', 
        depthOption: 'infinity', 
        ignoreExternalsOption: true, 
        local: '.', 
        remote: "http://jenkins.svn.link.edu/svn/my/repo"]],
    workspaceUpdater: [$class: 'UpdateUpdater']])
}

stage('Build webApp') {          
bat 'C:/"Program Files (x86)/Microsoft Visual Studio"/2017/Community/MSBuild/15.0/Bin/MSBuild.exe webApp/webApp.sln  /m /p:VisualStudioVersion=15.0'   //msbuild     
}

stage('Test: Check if IIS webApp ON') {
bat 'C:/"Program Files (x86)"/NUnit.org/nunit-console/nunit3-console.exe SeleniumNunit/SeleniumNunit/bin/Debug/SeleniumNunit.dll'
}

} catch (e) {
// If there was an exception thrown, the build failed
currentBuild.result = "FAILED"
throw e
} finally {
// Success or failure, always send notifications
notifyBuild(currentBuild.result)
}
} 

def notifyBuild(String buildStatus = 'STARTED') {
// build status of null means successful
buildStatus =  buildStatus ?: 'SUCCESSFUL'

emailext(
  to: '[email protected]',
  subject: "${buildStatus}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
  body: "details",
  recipientProviders: [[$class: 'DevelopersRecipientProvider']]
)
}

Can you identify any reasons why I am not receiving emails?

1

There are 1 answers

0
Lgalan90 On BEST ANSWER

So... I unchecked Use SMTP Authentication under Extended E-mail Notifications and it worked! I need to wrap my head around this now...