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)
...............
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.
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):
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With