如何在Jenkins管道中发布nunit3测试结果?

时间:2018-09-26 08:35:29

标签: jenkins jenkins-pipeline

我有一个定义如下的jenkinfile:

stages{
      stage("Unit Tests") {
        script {
          try {
            powershell "c:\\'Program Files (x86)'\\NUnit.org\\nunit-console\\nunit3-console.exe (ls -r *\\bin\\Debug\\*.UnitTests.dll | % { $_.FullName } | sort-object -Unique) --result=Caxton.OMX.DevelopBranch.UnitTests.xml"
          }
          catch (Exception err) {
            currentBuild.result = 'SUCCESS'
          }
        }

      stage("Integration Tests") {
        script {
          try {
            powershell "c:\\'Program Files (x86)'\\NUnit.org\\nunit-console\\nunit3-console.exe D:\\Jenkins\\workspace\\'Caxton.OMX (Build and run unit tests for develop branch)'\\Caxton.OMX.IntegrationTests\\bin\\Debug\\Caxton.OMX.IntegrationTests.dll --result=Caxton.OMX.DevelopBranch.IntegrationTests.xml"
          }
          catch (Exception err) {
            currentBuild.result = 'SUCCESS'
          }
        }
}

现在,我想在构建后操作中发布那些xml文件,该怎么办?我不知道nunit3的参数,但是应该是这样的:

post{
   nunit3 testResultFile ' ' ...
}

请向我提供Jenkinfile中nunit3参数的详细信息,或者在这种情况下的示例中更好(我想同时发布两个xml文件)。谢谢

2 个答案:

答案 0 :(得分:0)

我为此找到了解决方案。我将以下代码添加到后期构建中:

post
  {
    always
    {
      echo "publish the Nunit3 tests"
      step([
        $class: 'NUnitPublisher',
        testResultsPattern: "*.xml",
        debug: false,
        //keepJUnitReports: true,
        //skipJUnitArchiver:false,
        failOnError: true,
        //failIfNoResults: true
      ])
    }
  )

您可以添加更多参数,但是仅使用上面的3个即可将测试发布到Jenkins视图。希望能为与我有同样问题的任何人提供帮助。

答案 1 :(得分:0)

使用摘要生成器,我想到了以下对我有用的东西: enter image description here

    post {
        always {
            nunit testResultsPattern: 'TestResult.xml'
        }
    }

运行作业后,转到内部版本,您应该会在此处看到一份测试报告,其中列出了所有测试以及通过/失败结果。