问题描述
我有munit html报告和整合html报告。如果集成测试失败,则不会生成报告。我想仅向单元测试发送电子邮件通知,而不向集成测试发送电子邮件通知。 所以我尝试了if条件,但是我不知道如何在后期动作中让double适合条件。
如果有人建议我解决上述情况,这将非常有帮助。 而且我已经定义了以下变量,但是面临退出变量的问题。
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'
error: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'
预先感谢
解决方法
如果在现有内容之前放置 def ,则该内容仅在本地范围内可用,而在发布步骤中不再可用。删除 def ,MissingProperty异常应得到解决。
我不完全了解您要如何检查这些条件,但听起来可以使用布尔逻辑来完成。像这样:
if(exists && !exit){ ... }
,
我通过以下代码实现
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"
}
}
}