我有一个简单的管道脚本,该脚本在后期有两个阶段(测试阶段和后期),如果构建失败或不稳定,我会在其中发送通知。但是,我能够发送包含作业名称,内部版本号以及该作业在控制台中的控制台输出的通知,但是我还需要在通知本身中发送失败的测试报告的链接(我在Jenkins中的工作区文件夹作为HTML文件)
为此,我开发了一个groovy脚本(请参阅test.groovy),但是我不确定如何在后期的邮件块中(在后期)将其添加到管道脚本中
管道脚本
#!/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(我开发的用于在后期添加的代码)
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");
}
顺便说一句,我对詹金斯(Jenkins)和管道脚本还很陌生,我被困在这里,有人可以在这里帮助我。