如何修复'hudson.remoting.ProxyException:groovy.lang.MissingMethodException:方法无签名:testFunc.call()'

时间:2019-05-23 18:04:34

标签: jenkins groovy jenkins-pipeline shared-libraries

我正在尝试使用Jenkins中的共享库来调用函数。共享库groovy文件存在于存储库的/ vars文件夹中。

我已经尝试过使用共享库文件的其他名称。我也尝试使用testFunc.call(),testFunc,testFunc()

调用它

testFunc.groovy


import hudson.model.*
import hudson.EnvVars
import groovy.json.JsonSlurperClassic
import groovy.json.JsonBuilder
import groovy.json.JsonOutput
import groovy.json.*
import java.net.URL
def coveragepercentage
def testFunc(){

    def param = "${env:TestCoverage}"
    echo param
    def paramInt = param as int
    echo "Integer "+ paramInt
    def jsondata = readFile(file:'./target/site/munit/coverage/munit-coverage.json')
           def data = new JsonSlurperClassic().parseText(jsondata)
           coveragepercentage = data.coverage
           echo "${coveragepercentage}"

        if(coveragepercentage > paramInt){
           println("This value is smaller")
           sh "exit 1"
           currentBuild.result = 'FAILURE'
                }
}

使用上述共享库的Jenkins文件

@Library('shared-lib2') _
import hudson.model.*
import hudson.EnvVars
import groovy.json.JsonSlurperClassic
import groovy.json.JsonBuilder
import groovy.json.JsonOutput
import groovy.json.*
import java.net.URL
pipeline{
  agent any
    tools {
      maven 'Maven'
      jdk  'JAVA'
        }
    stages {
        stage('build') {
            steps {
                configFileProvider([configFile(fileId: 'config', variable: 'MAVEN_SETTINGS_XML')]) {
                sh "mvn -s $MAVEN_SETTINGS_XML clean package"
                }
            }
        }
        stage('test function'){
            steps{
                script{
                testFunc()
                }
            }
        }

        stage('MUnit Test Report') {
               steps{
                script {
                  publishHTML(target:[allowMissing: false,alwaysLinkToLastBuild: true,keepAll: true,reportDir: 'target/site/munit/coverage',reportFiles: 'summary.html',reportName: 'MUnit Test Report',reportTitles: 'MUnit Test Coverage Report'])
                }
                  }
            }   
    }

错误:hudson.remoting.ProxyException:groovy.lang.MissingMethodException:方法的无签名:testFunc.call()适用于参数类型:()值:[]

3 个答案:

答案 0 :(得分:0)

在您的testFunc.groovy中,您需要将功能从testFunc重命名为call()。进行此更改后,可以将您的函数作为声明步骤进行调用

答案 1 :(得分:0)

我的情况是

call() {

应该是

def call() {

丢脸。

答案 2 :(得分:0)

我将此添加到了常规应用中,并且对我有用。不知道这是否有帮助!

解决方案

def call(body) {
def config = [:]
body.resolveStrategy = Closure.DELEGATE_FIRST
body.delegate = config
body()

pipeline{
//your code
}
}
相关问题