我有munit html报告和integration html报告。如果在集成测试中出现任何故障,则不生成报告。我只想发送电子邮件通知munit测试,而不是集成测试。所以我尝试了if条件,但我不知道如何在赛后适应双if条件。
如果有人建议我一种解决上述问题的方法,那将非常有帮助。我已经定义了以下变量,但面临退出变量的问题。
FILE = "${DEMO}/${BUILD_NUMBER}/MunitReport-${BUILD_NUMBER}.html"
def exists = fileExists 'FILE'
REPO = "${DEMO}/${BUILD_NUMBER}/report/${BUILD_NUMBER}/htmlreport.html"
def exit = fileExists 'REPO'
错误:groovy.lang.MissingPropertyException:类groovy.lang.Binding不存在此类属性在groovy.lang.Binding.getVariable(Binding.java:63(
post {
always{
script{
if ((exists))
emailext attachLog: true, body: "${currentBuild.result}: <h4> MUnit test Results from Below link</h4> <h3>****/job/*****job/********/job/master/${BUILD_NUMBER}/Munit_20Report</h3> <h4>Integration test Results from Below link</h4> <h3>*********/job/********/job/*******/job/master/${BUILD_NUMBER}/Integration_20Test_20Report</h3>"", compressLog: true, replyTo: 'email@xxx.com',
subject: "Build Notification: ${JOB_NAME}-Build# ${BUILD_NUMBER} ${currentBuild.result}", to: 'email123@xxx.com'
提前感谢
如果在exist前面放一个def,它只在本地作用域中可用,在后步骤中不再可用。删除def,应该解决MissingProperty异常。
我不完全理解你想如何检查这些条件,但听起来可以用布尔逻辑来完成。类似于:
if(exists && !exit){ ... }
i使用以下代码实现
post {
always {
archiveArtifacts allowEmptyArchive: true, artifacts: 'munit.html', onlyIfSuccessful: true
archiveArtifacts allowEmptyArchive: true, artifacts: 'htmlreport.html', onlyIfSuccessful: true
emailext attachLog: true, attachmentsPattern: 'munit.html,htmlreport.html',
body: "<h4> ${currentBuild.currentResult}: </h4> Job: <h4> ${env.JOB_NAME}</h4> build: <h4>${env.BUILD_NUMBER}</h4>n More info at: <h4>${env.BUILD_URL}</h4>", compressLog: true, subject: "Jenkins Build ${currentBuild.currentResult}", to: "example@gmail.com"
}
}
}