英文:
Jenkins Declarative pipeline: send email notification with test report in post stage
问题
pipeline {
agent any
stages {
stage('Campaign Log') {
steps {
echo "RUNNING ${env.BUILD_ID} on ${env.JENKINS_URL}"
uiVeri5ExecuteTests script: this,
testRepository: "https://github.wdf.sap.corp/grc-iag-acert/qa.ui.automation.wdf.git",
gitBranch: "sg-pipeline",
testOptions: "-v --params.user='iag.administrator.testing@sap.com' --params.pass='Iagadministrator123@\$' ./logs/campaign_log/config.js --baseUrl=https://parrot-one-flp-iag-acert-qa-hcl.cfapps.sap.hana.ondemand.com/cp.portal/site#Shell-home";
}
}
}
post {
failure {
mail bcc: '', body: "Details: ${env.JOB_NAME} Build Number: ${env.BUILD_NUMBER} Build: ${env.BUILD_URL} Console Output: ${env.BUILD_URL}/console\n${SCRIPT_RESULT}", cc: '', from: 'noreply+jaas@sap.com', replyTo: '', subject: 'Failing UIVeri5 Tests', to: 'surendra.gurram@sap.com';
}
unstable {
mail bcc: '', body: "Details: ${env.JOB_NAME} Build Number: ${env.BUILD_NUMBER} Build: ${env.BUILD_URL} Console Output: ${env.BUILD_URL}/console\n${SCRIPT_RESULT}", cc: '', from: 'noreply+jaas@sap.com', replyTo: '', subject: 'Failing UIVeri5 Tests', to: 'surendra.gurram@sap.com';
}
}
}
英文:
I have a simple pipeline script with two stages (test stage and post-stage) in the post-stage, where I send a notification if the build is failed or unstable. However, I am able to send a notification with job name, build number and the console output of that job in the notification but I also need to send the link of the failing test report in the notification itself (I have the test reports in the workspace folder in Jenkins as HTML file)
For this, I have a developed a groovy script (see test.groovy) but I am not sure how to add this to the pipeline script in post-stage in the mail block (in the post-stage)
pipeline script
#!/usr/bin/env groovy
@Library(['piper-lib', 'piper-lib-os']) _
pipeline {
agent any
stages {
stage('Campaign Log') {
steps {
echo "RUNNING ${env.BUILD_ID} on ${env.JENKINS_URL}"
uiVeri5ExecuteTests script: this,
testRepository: "https://github.wdf.sap.corp/grc-iag-acert/qa.ui.automation.wdf.git",
gitBranch: "sg-pipeline",
testOptions: "-v --params.user='iag.administrator.testing@sap.com' --params.pass='Iagadministrator123@\$' ./logs/campaign_log/config.js --baseUrl=https://parrot-one-flp-iag-acert-qa-hcl.cfapps.sap.hana.ondemand.com/cp.portal/site#Shell-home"
}
}
}
post {
failure {
//def console_output = "${env.BUILD_URL}/console"
mail bcc: '', body: "Details: ${env.JOB_NAME} Build Number: ${env.BUILD_NUMBER} Build: ${env.BUILD_URL} Console Output: ${env.BUILD_URL}/console", cc: '', from: 'noreply+jaas@sap.com', replyTo: '', subject: 'Failing UIVeri5 Tests', to: 'surendra.gurram@sap.com'
}
unstable {
mail bcc: '', body: "Details: ${env.JOB_NAME} Build Number: ${env.BUILD_NUMBER} Build: ${env.BUILD_URL} Console Output: ${env.BUILD_URL}/console", cc: '', from: 'noreply+jaas@sap.com', replyTo: '', subject: 'Failing UIVeri5 Tests', to: 'surendra.gurram@sap.com'
}
}
}
test.groovy (The code I developed to add in post-stage)
test = new File($ {env.BUILD_URL} + '/execution/node/3/ws/logs/campaign_log/target/report/report.html').readLines()[160]
check = test.substring(18, test.length() - 7);
if (0 < check.toInteger()) {
println($ {env.BUILD_URL} + '/execution/node/3/ws/logs/campaign_log/target/report/report.html');
} else {
println("this test passed");
}
BTW I am pretty new to Jenkins and pipeline script, and I am stuck here, could someone help me here.
专注分享java语言的经验与见解,让所有开发者获益!
评论