jenkinsfile-无法调用java类函数CPSComilationErrorException-无法解析类

fhity93d  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(372)

我们需要在Jenkins文件中调用java类函数。从groovy类调用java函数时工作。但当java函数从Jenkins文件调用时,同样会失败。
java类:src/main/java

package package_java;

import java.io.Serializable;

public class JavaGroovy implements Serializable {

public void mul (){
System.out.println("Java function is called");

}}
groovy类-变量。还尝试将其放在src/main/java下-两者都没有帮助

import package_java.*

    class executeJava implements Serializable{
    JavaGroovy javaGroovy = new JavaGroovy(); 

    def setJava(){
       javaGroovy.mul()
       }}

Jenkins档案:


# !groovy

@Library(["com.dtcc.dal","com.dtcc.diaci", "com.dtcc.ddptest@currentBranch", "com.**.common"]) _

import groovy.json.JsonSlurperClassic
pipeline {
    agent { node { label "$NodeName" } }
    stages {
    stage('TC: Test calling java function') {

            steps {
                script {

                   println "git checkout repo "
                   ddpCommitHash = gitCheckout(ddp_repo, ddp_revision, "iac")

                   def utils = load "${env.WORKSPACE}/iac/vars/executeJava.groovy"
                   utils.setJava()
                  println "java function is called"

                }
            }
        }
    }
}

错误

org.jenkinsci.plugins.workflow.cps.CpsCompilationErrorsException: startup failed:

**Script1.groovy: 7: unable to resolve class JavaGroovy

@ line 7, column 3.
JavaGroovy javaGroovy = new JavaGroovy();
^
Script1.groovy: 7: unable to resolve class JavaGroovy
@ line 7, column 27.
JavaGroovy javaGroovy = new JavaGroovy();**

2 errors
at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:10)
atorg.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)
org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall
(SandboxInterceptor.java:157)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:161)

NOTE- Java class, groovy class are available in the workspace .

Please help . I guess i am missing something.

Thanks

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题