Jenkins与内部类共享库

时间:2018-04-09 08:20:54

标签: jenkins groovy

我试图将Jenkins共享库与内部类一起使用。当我尝试创建一个新的内部实例时它失败了。导入工作,所以我猜它不是我在詹金斯配置错误的东西。添加示例..

共享库:

package src.org.jenkins
class global_func implements Serializable {
  static class global_A implements Serializable {
    def steps
    global_A(steps) {
        this.steps = steps
    }
     def A_func() {
         return true
     }
   }
}

jenkins文件:

@Library('global_func')
import org.jenkins.global_func
global_utils = new global_func.global_A(steps)

错误日志:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup     
failed:
WorkflowScript: 38: unable to resolve class global_func.global_A 
@ line 38, column 13.
A = new global_func.global_A(steps)
     ^

1 error 
at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:958)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:605)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:554)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:129)
at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:123)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:517)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:480)
at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:253)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:421)
Finished: FAILURE

1 个答案:

答案 0 :(得分:0)

可能的问题:

  1. 该软件包的定义是:package src.org.jenkins
  2. 导入:import org.jenkins.global_func
  3. global_funcglobal_A的c'tor都没有定义,可能默认的c'tor对您来说还不够好。