如何访问作业dsl中的字符串参数

How to access the string parameters in job dsl

我将模板作业和 SVN 分支 URL 作为字符串参数传递给作业 dsl 脚本。 (使用参数化构建选项)。

def template = "${template_job}"
def url = "${svn_url}"
job('example') {
  using('template')
 configure { node ->
    node / scm / branches / 'hudson.scm.SubversionSCM_-ModuleLocation' / name('url')
  }
}

但我遇到了这样的错误:

Processing provided DSL script
ERROR: (script, line 1) No signature of method: script.$() is applicable for argument types: (script$_run_closure1) values: [script$_run_closure1@79b72972]
Possible solutions: is(java.lang.Object), run(), run(), any(), job(java.lang.String), any(groovy.lang.Closure)

有什么关于如何访问 job-dsl 中的字符串参数的建议吗?谢谢

您不需要将参数包装在字符串中。它们已经是字符串。如果您的参数是 template_jobsvn_url,这应该有效:

job('example') {
  using(template_job)
  configure { node ->
    node / scm / branches / 'hudson.scm.SubversionSCM_-ModuleLocation' / name(svn_url)
  }
}