我有一段 Jenkins 管道代码,我试图在我的角度代码上运行 JUnit。
如果单元测试失败,Jenkins 必须停止管道。
它正在工作,只是我看不到“最新测试结果”和“测试结果趋势”
我正在使用 Jenkins 2.19.1、Jenkins Pipeline 2.4 和 Junit 1.19。这是管道代码:
{
sh("npm install -g gulp bower")
sh("npm install")
sh("bower install")
try {
sh("gulp test")
} catch (err) {
step([$class: 'JUnitResultArchiver', testResults: '**/reports/junit/*.xml', healthScaleFactor: 1.0])
junit '**/reports/junit/*.xml'
if (currentBuild.result == 'UNSTABLE')
currentBuild.result = 'FAILURE'
throw err
}
}
知道我做错了什么吗?
如果您使用声明式管道,您可以执行以下操作:
pipeline {
agent any
stages {
stage('Build and Test') {
steps {
sh 'build here...'
sh 'run tests here if you like ...'
}
}
}
post {
always {
junit '**/reports/junit/*.xml'
}
}
}
这也可以用于 html 发布或任何东西,不需要finally/catch 等。它总是会存档结果。
See https://jenkins.io/doc/book/pipeline/syntax/#declarative-pipeline https://jenkins.io/doc/book/pipeline/syntax/#declarative-pipeline了解更多。
如果你有一个clean没有测试输出的目标:
post {
always {
junit(
allowEmptyResults: true,
testResults: '**/test-reports/*.xml'
)
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)