jenkins - 无法在Jenkins Pipeline中显示JUnit测试结果

标签 jenkins jenkins-pipeline

我有一段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/

相关文章:

groovy - Jenkinsfile管道DSL : How to Show Multi-Columns in Jobs dashboard GUI - For all Dynamically created stages - When within PIPELINE section

jenkins - 如何将用户输入密码与凭据密码进行比较

jenkins - "java.io.NotSerializableException: java.io.PrintWriter"写入文件时 - Jenkins 工作流程

jenkins - 删除一些测试用例后,当前执行报告中仍然显示旧的测试用例

Jenkins 民意调查 SCM 问题

android - Robolectric 2.x + Jenkins 上的 Maven 因 APKLIB 依赖项而失败

android - Jenkins 无法启动模拟器

jenkins - 声明式 Jenkins 管道中的检查点

c# - 使用 vstest.console.exe 工具运行 Selenium 测试时显示测试的 URL

python - 导入 python 模块失败