【问题标题】:jenkins job dsl - No signature of method: java.lang.String.call()jenkins job dsl - 没有方法签名:java.lang.String.call()
【发布时间】:2019-07-29 18:55:06
【问题描述】:

我无法运行这段代码:

buildPath = 'applications'
buildJob(['java', 'nodejs'])


def buildJob(def jobList){
  for(job in jobList){
    def jobName = "${job}_seed"
    def jobDescription = "Jenkins DSL seed for ${job}"
    def jobScriptPath = "resources/dsl/${jobName}.groovy"
    job("${buildPath}/${jobName}")
  }
}

所以,我收到了这个错误:

Processing provided DSL script
ERROR: (script, line 12) No signature of method: java.lang.String.call() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl) values: [applications/java_seed]
Possible solutions: wait(), any(), wait(long), take(int), each(groovy.lang.Closure), any(groovy.lang.Closure)
Finished: FAILURE

我看不到导致此错误的位置或原因。我在 buildJob(def jobList) 函数之外创建了一个工作,它正在工作,但我需要执行循环以自动化工作创建。

有什么想法吗?

【问题讨论】:

    标签: jenkins groovy dsl jenkins-groovy jenkins-job-dsl


    【解决方案1】:

    发布我遇到的类似问题。网络上关于这个问题的报道不多。

    No signature of method: java.lang.String.call() is applicable for argument types: (java.lang.String) values: [some-value]

    假设我们正在实现一个工作 dsl 插件 (https://github.com/jenkinsci/multibranch-build-strategy-extension-plugin),例如:

    includeRegionBranchBuildStrategy {
    
        includedRegions(String value)
    
    }
    

    我们有如下代码:

    def includedRegions = r ? String.join("\n", r) : null
    
    branchSources {
      branchSource {
        buildStrategies {
          if(includedRegions){
            includeRegionBranchBuildStrategy {
              includedRegions(includedRegions)
            }
          }
        }
      }
    }
    

    需要重命名变量才能使其工作!例如,方法不能与上面定义的 var 同名。

    def regions = r ? String.join("\n", r) : null
    
    branchSources {
      branchSource {
        buildStrategies {
          if(regions){
            includeRegionBranchBuildStrategy {
              includedRegions(regions)
            }
          }
        }
      }
    }
    

    【讨论】:

      【解决方案2】:

      您正在以下行中迭代字符串数组:

      for(job in jobList){
      

      并为此使用变量job

      然后你尝试在这个变量上调用方法call

      job("${buildPath}/${jobName}")
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-02-06
        • 1970-01-01
        • 2019-01-11
        • 1970-01-01
        • 2018-12-26
        • 1970-01-01
        • 2018-08-12
        相关资源
        最近更新 更多