我如何解决"期望的命名参数" for freeStyleJob?

时间:2017-09-27 14:00:20

标签: jenkins groovy jenkins-pipeline nexus

我有几个不同的项目将在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调用我创建的创建freeStyleJobs的uploadToNexus方法:

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需要一个我通过的字符串,不是吗?我错过了什么,做错了什么?

1 个答案:

答案 0 :(得分:2)

似乎我混淆了Job DSL和Pipeline DSL。我不知道有什么区别。

这是在Pipeline DSL中使用Job DSL的一种方法: https://github.com/jenkinsci/job-dsl-plugin/wiki/User-Power-Moves#use-job-dsl-in-pipeline-scripts