passing parameter to jenkins job through curl POST not working?
Asked Answered
P

7

20

I try to launch

curl -X POST -u "user:pass" -H Jenkins-Crumb:thecrumbnumber http://myjenkinsserver/jenkins/job/testjob/buildWithParameters?=PARAMETER=somenumber

which works by triggering a parametrized build, but the problem is no value is passed to the build (whats weird even when the token is set in the job, I can trigger the job without it). In jenkins, that job has a configured string "PARAMETER" with or without some default value, but never the parameter from the curl launch is passed. What I may be missing?

Pedi answered 22/3, 2017 at 9:0 Comment(0)
P
26

I'm using:

curl -X POST -u "user" "http://myjenkins/path/to/my/job/buildWithParameters?GERRIT_REFNAME=feature/retry&goal=package"

here and it's working like a charm.

Watch out the "=" in front of the "PARAMETER" in the URL you pasted.

Polarity answered 22/3, 2017 at 9:25 Comment(0)
I
14

Using curl form parameters (-F param1=value1) solved the problem:

# parameters need to be passed via: -F param1=value1 -F param2=value2 ...
curl -X POST http://myJenkins/job/testjob/buildWithParameters?token=<myToken> -F param1=value1

I had the same problem and none of the above helped. When I'm passing parameters via url parameters job is triggered but url parameters are not propagated.

# job is triggered but parameters are not propagated
curl -X POST http://myJenkins/job/testjob/buildWithParameters?token=<myToken>&param1=value1
Intramural answered 9/4, 2020 at 6:17 Comment(1)
Thanks. I had the exact same problem as you did and your solution works perfectly! Thanks!Savage
W
4

Please try something like:

curl -X POST http://<jenkins URL>/jenkins/job/TESTS/job/<Your job's Name>/buildWithParameters \
  --user <Jenkins account>:<account's TokenID>  \
  --data token=<job's token (if required)> \
  --data parameter=some_value
  ...
  --data MessageTextParameter=My%20Text
Warmblooded answered 17/10, 2017 at 10:9 Comment(0)
P
3

I used below command to pass Multiple parameter.

curl -X POST "https://myjenkins.com/job/jobname/buildWithParameters?token=developer&name=abc&userid=CFDH123&[email protected]"

Note: parameter names are case sensitive.

Patriarchy answered 10/1, 2019 at 9:57 Comment(0)
H
1

Looks like there is a typo in Jenkins Confluence page while calling Jenkins url passing parameters as JSON payload.. https://wiki.jenkins.io/display/JENKINS/Remote+access+API Tried with url suffix as build instead of buildWithParameters and it is working..

curl -X POST -u "user:token/password" "http://myjenkins/path/to/my/job/build --data-urlencode json='{"parameter": [{"name":"GERRIT_REFNAME", "value":"feature/retry"},{"name":"goal", "value":"package"}]}'

Hammon answered 3/3, 2020 at 14:47 Comment(0)
S
0

I found this to be very confusing and inconsistent especially when wanting to pass parameters in the body. The following is what I found to be the best approach for building with parameters (passing some parameters and using the specified defaults).

curl -X POST -u "user:pass" \
http://myjenkinsserver/jenkins/job/testjob/buildWithParameters \
-F PARAMETER=somenumber 

I also tried the following approaches and mentioning them because they appear in various documentation but don't appear to work correctly/as described.

The below submits a build (build vs buildWithParameters URL) and passes parameters BUT does not use any other default parameters.

curl -X POST -u "user:pass" \
http://myjenkinsserver/jenkins/job/testjob/build \
--data-urlencode json='{"parameter": [{"name":"PARAMETER", "value":"somenumber"}]}'

The below seems like it should work but I found that the parameter was not passed correctly.

curl -X POST -u "user:pass" \
http://myjenkinsserver/jenkins/job/testjob/build \
--data-urlencode json='{"parameter": [{"name":"PARAMETER", "value":"somenumber"}]}'
Sergeant answered 17/5, 2020 at 23:57 Comment(0)
C
0

both the below formats are working fine for me.

curl -X POST http://hostname:8080/job/first_pipeline/build  --user  siebelcrm:xxxxxx --data-urlencode json='{"parameter": [{"name":"Greetings", "value":"New123"}]} ' -H  "Jenkins-Crumb:xxxxx"

or

curl -X POST http://hostname:8080/job/first_pipeline/buildWithParameters?Greetings=New1  --user  Admin:xxxxx --data-urlencode json=' ' -H  "Jenkins-Crumb:xxxxx"
Casar answered 13/1, 2022 at 2:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.