Jenkins Pipeline Build using parameters

0 votes

I'm trying to execute an existing job ('jenkins-test-project-build') using the build method with Jenkins pipeline.

 build('jenkins-test-project-build', param1 : 'some-value')

When I try to execute this I get te following 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)
...

Jul 11, 2018 in Jenkins by Tyrion anex
• 8,700 points
16,393 views

2 answers to this question.

0 votes

This error occurs because you havent passed 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')
answered Jul 11, 2018 by Sophie may
• 10,610 points
0 votes

First, as @sophie may mentioned 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.

answered Aug 8, 2019 by Sirajul
• 59,230 points

Related Questions In Jenkins

0 votes
2 answers
0 votes
1 answer

Jenkins Pipeline using Openshift

Create a new service account in openshift ...READ MORE

answered Aug 8, 2018 in Jenkins by Kalgi
• 52,360 points
701 views
0 votes
1 answer

Program to execute Dockerfile using Jenkins declarative pipeline

Hey @Nishant, you can use something like ...READ MORE

answered Apr 15, 2019 in Jenkins by Kalgi
• 52,360 points
2,016 views
+1 vote
1 answer
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
3,503 views
+2 votes
1 answer
0 votes
1 answer

Jenkins: Build Pipeline Plugin Scheduled Trigger

This can be done by setting the ...READ MORE

answered Jul 11, 2018 in Jenkins by Sophie may
• 10,610 points
4,409 views
+5 votes
3 answers

How to trigger a Jenkins pipeline A in another Jenkins pipeline B?

You can run the following code, its ...READ MORE

answered Jul 5, 2018 in Jenkins by Sophie may
• 10,610 points
117,452 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP