We are implemented CI/CD pipeline using Jenkins on Performance center (LoadRunner Cloud (SAAS offering)).
Email notification plugins downloaded and done the SMTP configurations. New Pipeline job implemented with post results email notification its not working below is the code I am using. Please help on this email notification.
pipeline {
agent any
stages {
stage('Execute') {
steps {
echo "Starting the performance test "
lrcRunTest testId: "111", projectId: '4', sendEmail: true
echo "Test completed"
}
}
}
post {
always {
script {
// Define the workspace location
def workspaceLocation = "C:\\Users\\atsadmin\\AppData\\Local\\Jenkins\\.jenkins\\workspace"
// Use sh step to find the latest file
def html = sh(script: "find ${workspaceLocation} -name 'lrc_report_trans_561249410-*.html' -exec sh -c 'basename {}' \\; | cut -d '-' -f2 | sort -nr | head -n 1", returnStdout: true).trim()
def csv = sh(script: "find ${workspaceLocation} -name 'lrc_report_trans_561249410-*.csv' -exec sh -c 'basename {}' \\; | cut -d '-' -f2 | sort -nr | head -n 1", returnStdout: true).trim()
def xml = sh(script: "find ${workspaceLocation} -name 'lrc_report_trans_561249410-*.xml' -exec sh -c 'basename {}' \\; | cut -d '-' -f2 | sort -nr | head -n 1", returnStdout: true).trim()
def pdf = sh(script: "find ${workspaceLocation} -name 'lrc_report_trans_561249410-*.pdf' -exec sh -c 'basename {}' \\; | cut -d '-' -f2 | sort -nr | head -n 1", returnStdout: true).trim()
// Construct the latest file name
// echo "$highestNumber"
def htmlFile = "lrc_report_trans_561249410-${html}"
def csvFile = "lrc_report_trans_561249410-${csv}"
def xmlFile = "lrc_report_trans_561249410-${xml}"
def pdfFile = "lrc_report_trans_561249410-${pdf}"
// Check if the file exists before attaching
if (fileExists(file: htmlFile)) {
// Send email with attachment
emailext(
attachmentsPattern: "${htmlFile},${csvFile},${xmlFile},${pdfFile}",
to: '${EMAIL_RECIPIENTS}',
subject: 'Performance Test Run Completed',
body: 'My test results'
//uncomment the below line if you want build logs in email
//attachLog: true
)
} else {
println "No HTML file found with the highest number."
}
}
}
}
}