詹金斯无法通过脚本管道中的getAction找到类

时间:2019-01-22 14:33:20

标签: jenkins jenkins-pipeline

在共享库中,我想读取PMD,FindBugs和CheckStyle的结果。 我的.jelly电子邮件模板中已经具有此功能。看起来像这样:

def pmd = it.getAction('hudson.plugins.pmd.PmdResultAction')
def fb = it.getAction('hudson.plugins.findbugs.FindBugsResultAction')
def cs = it.getAction('hudson.plugins.checkstyle.CheckStyleResultAction')

if (pmd != null || fb != null || cs != null) {        
    if (pmd != null) {   println "    PMD:        " + pmd.result.numberOfWarnings }
    if (fb != null)  {   println "    FindBugs:   " + fb.result.numberOfWarnings }
    if (cs != null)  {   println "    CheckStyle: " + cs.result.numberOfWarnings }
}

这有效。 现在,我想在脚本管道中实现这一点:

def getAction(Class actionClass) {
    // getCurrent() returns the currentBuild
    return getCurrent().rawBuild.getAction(actionClass)
}

[...]

def pmd = build.getAction(PmdResultAction.class)        
def fb = build.getAction(FindBugsResultAction.class)    
def cs = build.getAction(CheckStyleResultAction.class)  

def pmdCount = pmd ? pmd.result.numberOfWarnings : 0
def fbCount = fb  ? fb.result.numberOfWarnings : 0  
def csCount = cs  ? cs.result.numberOfWarnings : 0  

def warnings = []                                   
if (pmdCount > 0) warnings << "PMD: " + pmdCount    
if (fbCount > 0) warnings << "FB: " + fbCount       
if (csCount > 0) warnings << "CS: " + csCount       

当然可以正确导入

import hudson.plugins.pmd.PmdResultAction
import hudson.plugins.findbugs.FindBugsResultAction
import hudson.plugins.checkstyle.CheckStyleResultAction

但是如果我删除FindBugs,此操作将失败,并显示ERROR: hudson.plugins.findbugs.FindBugsResultActionERROR: hudson.plugins.checkstyle.CheckStyleResultAction

该机制之所以起作用,是因为我可以成功读取getAction(AbstractTestResultAction.class)以获得测试结果。

关于如何执行此操作的任何想法?

0 个答案:

没有答案