Invoking the /build endpoint for a job with curl dropping parameters not explicitly passed via json

28 views
Skip to first unread message

Jay Hayes

unread,
Feb 20, 2020, 9:35:29 AM2/20/20
to Jenkins Users
Hello,

This seems like a bug to me but, if so, I don't know how it hasn't been reported which makes me think I'm overlooking something obvious.

When I invoke a jenkins job via curl and send the parameters as JSON data\payload to the job's /build endpoint any parameters I don't pass in the payload disappear from the invoked build for that job (even if the parameters omitted have default values).

For instance, say I have a job test-job with the following parameters defined:

String Parameter
[Help]
 NameHelp for feature: Name
 Default ValueHelp for feature: Default Value
 Description
 
[Safe HTML] Preview 
Help for feature: Description
 Help for feature: This project is parameterized
String Parameter
[Help]
 NameHelp for feature: Name
 Default ValueHelp for feature: Default Value
 Description
 
[Safe HTML] Preview 


If i invoke said job via curl using the /build endpoint:
curl --location --request POST 'http://XXXXXXXXXXXXXXX:8080/job/test-job/build' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Authorization: XXXXXXXXXXXXXXXXXXXXXXX' \
--data-urlencode 'json={"parameter":[{"name":"required_param","value":"myValue"}]}'

The default_param is dropped entirely from the resultant build:

Build #8

Parameters
 required_param








Instead if I invoke the job via curl with url query params using the /buildWithParameters endpoint it works as I would expect:

curl --location --request POST 'http://XXXXXXXXXXXXXXX:8080/job/test-job/buildWithParameters?required_param=myValue' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Authorization: XXXXXXXXXXXXXXXXXXXXXXX'

Build #9

Parameters
 required_param
 default_param












Is there a bug with the /build endpoint WRT passing parameters as json data?

Thanks,
Jay



Mark Waite

unread,
Feb 20, 2020, 10:20:19 AM2/20/20
to Jenkins Users
I suspect that is intentional.  I assume that the '/build' end point is not intended for use with parameters.  If you want to pass parameters, use the /buildWithParameters end point.


--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/5313272d-8c6a-49c9-9509-94be90d71af9%40googlegroups.com.

Jay Hayes

unread,
Feb 20, 2020, 11:00:04 AM2/20/20
to Jenkins Users
Fair enough but, for whatever reason, I can only get the parameters passed as JSON data when I use the /build endpoint.  If I POST to the /buildWithParameters endpoint, all parameters show up in the invoked build but with no values (other than defaults).

Using the same example with the following curl:
curl --location --request POST 'http://XXXXXXXXXXXXXXXXXXX:8080/job/test-job/buildWithParameters' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Authorization: XXXXXXXXXXXXXXXXXXXXX' \
--data-urlencode 'json={"parameter":[{"name":"required_param","value":"myValue"}]}'

Yields:

Build #11

Parameters
 required_param
 default_param











The default_param is now included with the correct default value but the value passed for the required_param is missing?

To unsubscribe from this group and stop receiving emails from it, send an email to jenkins...@googlegroups.com.

Sushmitha Krishnan

unread,
May 29, 2020, 5:50:27 AM5/29/20
to Jenkins Users
Hai.. I need to send the whole json string to the jenkin's parameter. Do u have any idea how to do that.

**********************************************************************
This email is confidential and may contain copyright material of the John Lewis Partnership.
If you are not the intended recipient, please notify us immediately and delete all copies of this message.
(Please note that it is your responsibility to scan this message for viruses). Email to and from the
John Lewis Partnership is automatically monitored for operational and lawful business reasons.
**********************************************************************

John Lewis plc
Registered in England 233462
Registered office 171 Victoria Street London SW1E 5NN

Websites: https://www.johnlewis.com
http://www.waitrose.com
https://www.johnlewisfinance.com
http://www.johnlewispartnership.co.uk

**********************************************************************

Reply all
Reply to author
Forward
0 new messages