Reputation: 240
I'm trying to execute an already defined job using build method with jenkins pipeline. This is a simple example:
build('jenkins-test-project-build', param1 : 'some-value')
But when I try to execute it I get an error:
java.lang.IllegalArgumentException: Expected named arguments but got [{param1=some-value}, jenkins-test-project-build]
at org.jenkinsci.plugins.workflow.cps.DSL.parseArgs(DSL.java:442)
at org.jenkinsci.plugins.workflow.cps.DSL.parseArgs(DSL.java:380)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:156)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:126)
...............
Upvotes: 5
Views: 40305
Reputation: 1683
Use the pipeline code generator of the specific jenkins server to generate the code, in my case this was happening because of version mismatch, we use a different version for development then production and each used a different syntax to call a job and pass parameters.
Upvotes: 2
Reputation: 7880
You have multiple issues in your build call.
First, as sshepel mentionned it you should name your parameters if you have more than one (you can forget to name it only if you only use the default parameter job
, e.g. build 'my-simple-job-without-params'
).
The second problem is that you are not passing parameters correctly. To pass parameters to a downstream job, you should use the parameter named parameters
and give it an array of objects that define each of your parameters, e.g. :
build job: 'jenkins-test-project-build', parameters: [[$class: 'StringParameterValue', name: 'param1', value: "some-value" ]]
Also, note that parenthesis are optional in a Groovy method call.
Upvotes: 16
Reputation: 890
You are getting this error, because you didn't pass the name of the attribute which should store 'jenkins-test-project-build'.
In your case you should pass job attribute.
build(job: 'jenkins-test-project-build', param1 : 'some-value')
Here are the list of available options(pipeline-build-step):
Upvotes: 12