Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins Pipeline - Build with parameters

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)
...............
like image 663
andi Avatar asked Nov 27 '22 20:11

andi


2 Answers

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.

like image 186
Pom12 Avatar answered Dec 04 '22 05:12

Pom12


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):

  • job
  • parameters (optional)
  • propagate (optional)
  • quietPeriod (optional)
  • wait (optional)
like image 24
sshepel Avatar answered Dec 04 '22 07:12

sshepel