我有一段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等。它将始终将结果存档。有关更多信息,请参见https://jenkins.io/doc/book/pipeline/syntax/#declarative-pipeline。
如果目标干净,没有测试输出,请执行以下操作:
post {
always {
junit(
allowEmptyResults: true,
testResults: '**/test-reports/*.xml'
)
}
关于jenkins - 无法在Jenkins Pipeline中显示JUnit测试结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41230668/