如何为 freeStyleJob 解决 "Expected named arguments"?

How do I solve "Expected named arguments" for freeStyleJob?

我有几个不同的项目将在 Jenkins 中编译并上传到我的 Nexus3 存储库。为此,我正在使用 NexusArtifcalUploader。出于某种原因,尽管代码基本上是从 Jenkins wiki 的插件页面复制的,但我收到以下错误消息。

java.lang.IllegalArgumentException: Expected named arguments but got [clientmoduleNexusArtifactUploaderJob, org.jenkinsci.plugins.workflow.cps.CpsClosure2@63d801fc]
  at org.jenkinsci.plugins.workflow.cps.DSL.parseArgs(DSL.java:511)
  at org.jenkinsci.plugins.workflow.cps.DSL.invokeDescribable(DSL.java:291)
  at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:153)
  at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:108)
  at sun.reflect.GeneratedMethodAccessor463.invoke(Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:498)
  ...

我的 Jenkinsfile 调用我创建的 uploadToNexus 方法来创建 freeStyleJobs:

def uploadToNexus(module) {
  def groupId = "com.example"
  def moduleVersions = [
          "client-module": "1.0.0-SNAPSHOT",
          "server-module": "1.0.0-SNAPSHOT",
  ]

  def moduleVersion = moduleVersions.get(module)
  def jobName = "${fixModuleName(module)}NexusArtifactUploaderJob"

  echo "will run freeStyleJob ${jobName} now..."
  freeStyleJob(jobName) {
    steps {
      nexusArtifactUploader {
        nexusVersion('nexus3')
        protocol('http')
        nexusUrl('nexus:8081')
        groupId(groupId)
        version(moduleVersion)
        repository('maven2_central')
        credentialsId('nexus_admin')
        artifact {
          artifactId('${module}')
          type('war')
          classifier('debug')
          file('${module}.war')
        }
      }
    }
  }
}

据我所知,freeStyleJob 需要我传递的字符串,不是吗?我错过了什么和做错了什么?

看来我混淆了 Job DSL 和 Pipeline DSL。我不知道有什么不同。

这是在管道 DSL 中使用作业 DSL 的方法: https://github.com/jenkinsci/job-dsl-plugin/wiki/User-Power-Moves#use-job-dsl-in-pipeline-scripts