【问题标题】:Get amount of passed and failed jenkins tests from another jenkins job with pipeline使用管道从另一个詹金斯作业中获取通过和失败的詹金斯测试数量
【发布时间】:2018-01-25 02:56:44
【问题描述】:

我从我的 jenkins 管道开始 Jenkins 工作 job_name1

build job: 'job_name1', parameters: [ string(name: 'name1', value: 'value1') ], propagate: false

Job job_name1 已执行,它有 100 个通过了 JUnit 的 10 个失败的测试。

如何获得通过和失败的测试数量? 我试过了:

import hudson.model.Run
import hudson.tasks.junit.TestResultAction
import org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper
import hudson.model.Action

node("node_name")
{
   def my_build = build(job: 'job_name1', parameters: [ string(name: 'name1', value: 'value1') ], propagate: false,)
   defresults = (my_build as Run).getAction(TestResultAction) 
   def allTests = results.getResult()
   def failedTests = results.getFailCount()
}

并得到以下错误

hudson.remoting.ProxyException: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper@7c845e2' with class 'org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper' to class 'hudson.model.Run'

我该怎么做? 是否有可能以不同的方式做到这一点?

【问题讨论】:

    标签: jenkins groovy jenkins-pipeline


    【解决方案1】:

    您应该调用RunWrapper#getRawBuild 来获取实际的Run 对象

    defresults = my_build.rawBuild.getAction(TestResultAction) 
    

    【讨论】:

    • 感谢您的回答!我试过了,但出现错误org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use method org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper getRawBuild at org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.StaticWhitelist.rejectMethod(StaticWhitelist.java:175)
    • @nick_gabpe 您必须批准 RunWrapper#getRawBuild 以及您使用的其他方法。在documentation中查看更多详细信息
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-03
    • 1970-01-01
    相关资源
    最近更新 更多