无法在Jenkins Pipeline中显示JUnit测试结果 [英] Not able to display JUnit tests result in Jenkins Pipeline
问题描述
我有一段Jenkins管道代码,试图在我的角度代码上运行JUnit.
I have a piece of Jenkins pipeline code in which I am trying to run JUnit on my angular code.
如果单元测试失败,则詹金斯必须停止管道. 除了我看不到最新测试结果"和测试结果趋势"之外,它都可以正常工作
If the unit tests fail, Jenkins has to stop the pipeline. It's working except I am not able to see "Latest test Result" and "Test Result Trend"
我正在使用Jenkins 2.19.1,Jenkins Pipeline 2.4和Junit 1.19.这是管道代码:
I am using Jenkins 2.19.1, Jenkins Pipeline 2.4 and Junit 1.19. Here is the pipeline code:
{
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
}
}
知道我在做什么错吗?
推荐答案
仅供参考,如果您使用声明性管道,则可以执行以下操作:
FYI if you use declarative pipeline, you can do something like:
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等.它将始终存档结果.
This could also work with html publishing or anything, no need for finally/catch etc. it will always archive the results.
请参见 https://jenkins.io/doc/book/book/pipeline/语法/#declarative-pipeline 了解更多
这篇关于无法在Jenkins Pipeline中显示JUnit测试结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!