Reputation: 1598
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?
Upvotes: 20
Views: 78342
Reputation: 91
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"}]}'
Upvotes: 1
Reputation: 1
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"
Upvotes: 0
Reputation: 4366
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>¶m1=value1
Upvotes: 14
Reputation: 178
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"}]}'
Upvotes: 0
Reputation: 311
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
Upvotes: 4
Reputation: 741
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.
Upvotes: 3
Reputation: 386
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.
Upvotes: 26