selenium - Jenkins JUnit 保留结果,即使它已经被清理了
问题描述
我有一个包含 2 个阶段的 Jenkins 管道,它们都使用 JUnit 清理和计算测试结果。我的问题是,当我现在运行第 2 阶段时,Jenkins JUnit 仍然能够从第 1 阶段计算清理后的测试输出目录。这怎么可能?我只想计算第 2 阶段的测试结果。
stage('1'){
//Insert code to delete test-output directory here
//Insert build trigger here
junit '***/test-output/TEST-*.xml'
script {
AbstractTestResultAction testResultAction = currentBuild.rawBuild.getAction(AbstractTestResultAction.class)
if (testResultAction != null) {
def totalNumberOfTests = testResultAction.totalCount
def failedNumberOfTests = testResultAction.failCount
def failedDiff = testResultAction.failureDiffString
def skippedNumberOfTests = testResultAction.skipCount
def passedNumberOfTests = totalNumberOfTests - failedNumberOfTests - skippedNumberOfTests
emailTestReport = "Tests Report:\n Passed: ${passedNumberOfTests}; Failed: ${failedNumberOfTests} ${failedDiff}; Skipped: ${skippedNumberOfTests} out of ${totalNumberOfTests} "
}
}
mail to: 'example@email.com',
subject: "Tests are finished: ${currentBuild.fullDisplayName}",
body: "Tests are finished ${env.BUILD_URL}\n Test Report: ${emailTestReport} "
}
}
}
stage('2'){
//Insert Code to delete test-output directory here
//Insert build trigger here
junit '***/test-output/TEST-*.xml'
script {
AbstractTestResultAction testResultAction = currentBuild.rawBuild.getAction(AbstractTestResultAction.class)
if (testResultAction != null) {
def totalNumberOfTests = testResultAction.totalCount
def failedNumberOfTests = testResultAction.failCount
def failedDiff = testResultAction.failureDiffString
def skippedNumberOfTests = testResultAction.skipCount
def passedNumberOfTests = totalNumberOfTests - failedNumberOfTests - skippedNumberOfTests
emailTestReport = "Tests Report:\n Passed: ${passedNumberOfTests}; Failed: ${failedNumberOfTests} ${failedDiff}; Skipped: ${skippedNumberOfTests} out of ${totalNumberOfTests} "
}
}
mail to: 'example@email.com',
subject: "Tests are finished: ${currentBuild.fullDisplayName}",
body: "Tests are finished ${env.BUILD_URL}\n Test Report: ${emailTestReport} "
}
}
}
解决方案
通过调用 junit(...) 步骤,给定的测试结果将被解析并注册到构建运行中。要执行测试结果的“清理”,仅从工作区中删除测试报告文件是没有帮助的。相反,必须从内部构建模型中删除相应的值。这可以通过从构建中检索AbstractTestResultAction并设置一个新的(空的)TestResult 来实现。像这样尝试:
AbstractTestResultAction testResultAction = currentBuild.rawBuild.getAction(AbstractTestResultAction.class)
def listener = Jenkins.get().getItemByFullName(env.JOB_NAME).getBuildByNumber(Integer.parseInt(env.BUILD_NUMBER)).getListener()
testResultAction.setResult(new TestResult(), listener)
推荐阅读
- r - 安装依赖于其他自定义包的自定义包
- r - lapply 在尝试堆叠栅格时创建无限循环
- git - 可以从私有 GitHub 存储库克隆和拉取,但不能拉取
- db2 - 在 db2 中的某个时间后杀死应用程序用户
- identityserver4 - Identity Server 4 重定向到开发 URL 而不是生产
- amazon-cloudwatch - 如何转换 CloudWatch 中的字段类型?
- css - 如何在引导程序中删除额外的填充
- angular - 在 oidc-client 中验证状态和随机数
- c++ - 在反应器内存储事件处理程序的最佳方式是什么
- swift - 使用 swift 以编程方式发送消息