在Jenkinsfile中执行"发布TestNG结果"步骤

Gil*_*RET 5 jenkins jenkins-pipeline

我正在尝试将现有的一组Jenkins作业转换为新的管道语法,我不明白如何转换后构建操作"发布TestNG结果".管道语法页面没有帮助,因为未列出此特定操作,因此我尝试了以下语法:

step([$class: 'hudson.plugins.testng.Publisher', reportFilenamePattern: 'test-output/testng-results.xml'])
Run Code Online (Sandbox Code Playgroud)

我的假设是类名必须与当前配置中config.xml的内容相匹配:

<hudson.plugins.testng.Publisher plugin="testng-plugin@1.10">
  <reportFilenamePattern>test-output/testng-results.xml</reportFilenamePattern>
  <escapeTestDescp>true</escapeTestDescp>
  <escapeExceptionMsg>true</escapeExceptionMsg>
  <showFailedBuilds>false</showFailedBuilds>
  <unstableOnSkippedTests>false</unstableOnSkippedTests>
  <failureOnFailedTestConfig>false</failureOnFailedTestConfig>
</hudson.plugins.testng.Publisher>
Run Code Online (Sandbox Code Playgroud)

但是,执行语句时会抛出异常:

java.lang.IllegalArgumentException: argument type mismatch
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
  at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
  at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:193)
  at org.jenkinsci.plugins.workflow.steps.StepDescriptor.newInstance(StepDescriptor.java:104)
  at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:134)
  at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:113)
  at groovy.lang.GroovyObject$invokeMethod.call(Unknown Source)
  at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
  at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
  at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:151)
  at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:21)
  at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:115)
  at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:149)
  at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:146)
  at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:123)
  at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:123)
  at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:15)
  at WorkflowScript.testBranch(WorkflowScript:71)
Run Code Online (Sandbox Code Playgroud)

所以我的问题是:

  • 是否可以使用'step'语句触发任何类型的作业后操作?
  • 如果是,是否有经验法则可以找到类名和属性名?

如果与问题相关,我运行Jenkins 2.8,所有管道插件都是最新的,并且可以在GitHub上找到完整的Jenkins文件

use*_*510 14

现在可以在管道中发布TestNG测试结果.使用:

step([$class: 'Publisher'])
Run Code Online (Sandbox Code Playgroud)

或者使用结果文件的自定义位置:

step([$class: 'Publisher', reportFilenamePattern: '**/custom/testng-results.xml'])
Run Code Online (Sandbox Code Playgroud)

根据Jenkins Jira的评论,添加到Pipeline片段生成器正在等待中.

(在Jenkins 2.9.13和Pipeline插件2.4上测试)


Jas*_*ger 5

目前,TestNG 插件与 Pipelines 不兼容。参见JENKINS-27121