0

我创建了一个管道,该管道接受一组 JSON 对象,并将调用一个共享库,该库将迭代 JSON 对象

尝试运行 Jenkins 作业以测试我是否可以转发对象但我看到以下错误:

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)

代码:

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
    }
  }
4

1 回答 1

0

看起来imageBuild共享库 Jenkins-shared lib-cooking@BB-3611 中的 groovy 方法或全局变量不需要任何参数,但您正在尝试传递字符串,这就是您收到 MissingMethodException 的原因。与细节

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

要解决此问题,您必须将共享库方法或全局变量 imageBuild 从imageBuild()更改为imageBuild(String param) or imageBuild(def param)

我将尝试用与您的示例类似的示例进行说明,以供您参考。

假设您在名为 - jenkins-sharedlib-cooking-lifecycle 的 git 存储库中有一个共享库,并且您遵循 Jenkins 共享库文档建议的文件夹结构

// 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)
  }
}
于 2020-07-28T10:32:52.760 回答