简体   繁体   中英

jenkinspipeline groovy.lang.MissingMethodException: No signature of method

I have created a pipeline that takes an array of JSON objects and will call a shared library which will iterate over the JSON objects

When trying to run the Jenkins job to test that I can forward the objects but I'm seeing the following error:

hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: imageBuild.call() is applicable for argument types: (java.lang.String) values: [[{"dockerConfig":"home/pipelines/conf/journeys/dockerbuild.yaml","aquaConfig":"home/pipelines/conf/journeys/aquascan.yaml","gtag": "v1.0.1","preFixName": "journey1"},{"dockerConfig":"home/pipelines/conf/if.com/dockerbuild.yaml","aquaConfig":"home/pipelines/conf/if.com/aquascan.yaml","gtag": "v2.0.2","preFixName": "journey2"},{"dockerConfig":"home/pipelines/conf/colleague/dockerbuild.yaml","aquaConfig":"home/pipelines/conf/colleague/aquascan.yaml","gtag": "v3.0.3","preFixName": "journey2"}]]
Possible solutions: call(), call(java.util.Map), wait(), any(), wait(long), main([Ljava.lang.String;)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58)

Code:

library identifier: 'jenkins-sharedlib-cooking@BB-3611', retriever: modernSCM([$class: 'GitSCMSource',
 remote: 'https://github.com/lbg-gcp-foundation/jenkins-sharedlib-cooking-lifecycle.git',
 credentialsId: 'jenkinsPAT'])

def configList = '[{"dockerConfig":"home/pipelines/conf/journeys/dockerbuild.yaml","aquaConfig":"home/pipelines/conf/journeys/aquascan.yaml","gtag": "v1.0.1","preFixName": "journey1"},{"dockerConfig":"home/pipelines/conf/if.com/dockerbuild.yaml","aquaConfig":"home/pipelines/conf/if.com/aquascan.yaml","gtag": "v2.0.2","preFixName": "journey2"},{"dockerConfig":"home/pipelines/conf/colleague/dockerbuild.yaml","aquaConfig":"home/pipelines/conf/colleague/aquascan.yaml","gtag": "v3.0.3","preFixName": "journey2"}]'

pipeline {
  environment {
    def config = 
    brand = 
    environmentName = 
    CLUSTER_NAME = 
    CLUSTER_PROJECT = 
    VERSION = '1.0.0'
  }

  options {
    ansiColor('xterm')
    timeout(time: 150, unit: 'MINUTES')
    disableConcurrentBuilds()
    buildDiscarder(logRotator(numToKeepStr: '100'))
  }

  agent {
    kubernetes {
      label "jrn-${UUID.randomUUID().toString()}"
      yamlFile "pipelines/conf/podTemplate.yaml"
    }
  }
stages {
    stage('Stage 6 - Docker Image ') {
      parallel {
        stage ('Docker Image - Journeys') {
          steps {
            echo "*********************** Docker Journeys ***********************************"
            container('docker') {
              echo "Building the docker image..."
imageBuild(configList)
            }
            archiveArtifacts artifacts: "*.html", allowEmptyArchive: true
          }
        }
      }enter code here
    }
  }

Looks like the groovy method or global variable imageBuild in the shared library Jenkins-shared lib-cooking@BB-3611 does not expecting any parameter but you are trying to pass a string, that's the reason you are getting MissingMethodException. with the details

hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: imageBuild.call() is applicable for argument types: (java.lang.String) values

To fix the issue, you have to change the shared library method or global variable imageBuild from imageBuild() to imageBuild(String param) or imageBuild(def param)

I will try to illustrate with an example similar to your example for your reference.

Assuming you have a shared library in a git repository named - jenkins-sharedlib-cooking-lifecycle and you are following the folder structure suggested by Jenkins shared library documentation

// vars/imageBuild.groovy
import groovy.json.JsonSlurper
def call(def imagebuildParameter) {
  def jsonSlurper = new JsonSlurper()
  def object = jsonSlurper.parseText(imagebuildParameter)
  // use loop on object to retrive the value like below  
  println object[0].name
}

//Jenkinsfile
node {
  stage('stageName') {
    def x = '[{"name": "foo"},{"name": "bar"}]'
    imageBuild(x)
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM