Remote Build Using Curl

361 views
Skip to first unread message

Greg Nifor

unread,
Aug 17, 2015, 2:41:13 PM8/17/15
to Jenkins Users
Is there a way to use curl to send both a file and string parameter. I can do each individually, but not together.

Works:

curl -X POST <jenkins_url>/job/<job>/buildWithParameters -u <user>:<password> -F file=@/path/to

curl -X POST <jenkins_url>/job/<job>/buildWithParameters -u <user>:<password> --data string0=foo --data string1=bar

Doesn't Work:

curl -X POST <jenkins_url>/job/<job>/buildWithParameters -u <user>:<password> -F file=@/path/to --data string0=foo --data string1=bar

The result I get is: Warning: You can only select one HTTP request!


Any ideas?

Walter Kelt

unread,
Aug 17, 2015, 2:48:05 PM8/17/15
to jenkins...@googlegroups.com
You need to use the curl -F switch to make it a multipart http submission. This will allow a file and parameter to be included with a single http post submission. Plenty of online examples available.

Sent from my iPad
--
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/65067202-61bf-40b8-8509-376d5ae79589%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Walter Kelt

unread,
Aug 17, 2015, 2:49:09 PM8/17/15
to jenkins...@googlegroups.com
You need to use -F for file and -F for data.

Sent from my iPad

On Aug 17, 2015, at 2:41 PM, Greg Nifor <whiteho...@gmail.com> wrote:

Greg Nifor

unread,
Aug 17, 2015, 3:06:13 PM8/17/15
to Jenkins Users
When I try that the variables are empty.

Walter Kelt

unread,
Aug 17, 2015, 3:11:08 PM8/17/15
to jenkins...@googlegroups.com
Please paste your full curl command

Sent from my iPad

Greg Nifor

unread,
Aug 17, 2015, 3:15:57 PM8/17/15
to Jenkins Users
curl -X POST localhost/job/Test/buildWithParameters -u user:pass -F git=test -F root=root1

Walter Kelt

unread,
Aug 17, 2015, 3:19:24 PM8/17/15
to jenkins...@googlegroups.com
I think you need quote signs around each of the  -F items....such as -F "git=test"

Sent from my iPad

Greg Nifor

unread,
Aug 17, 2015, 3:27:54 PM8/17/15
to Jenkins Users
That didn't work.

Walter Kelt

unread,
Aug 17, 2015, 3:28:20 PM8/17/15
to jenkins...@googlegroups.com
Also, the url is usually after all the switches. Not sure how strictly the format is checked.

Sent from my iPad

Greg Nifor

unread,
Aug 17, 2015, 3:30:48 PM8/17/15
to Jenkins Users
No dice.

Walter Kelt

unread,
Aug 17, 2015, 3:32:48 PM8/17/15
to jenkins...@googlegroups.com
What was the error message ?  paste the most current command. Also, windows or Linux ?

Sent from my iPad

Greg Nifor

unread,
Aug 17, 2015, 3:45:15 PM8/17/15
to Jenkins Users
Linux, there's no errors. The command goes through, but Jenkins doesn't pick up on the variables when I echo them out this is the output:

12:31:06
+ echo 12:31:06 12:31:06 + echo root 12:31:06 root

Top one echos git and the second one echoes root (it's default value is root)
echo $git
echo $root

Walter Kelt

unread,
Aug 17, 2015, 3:57:38 PM8/17/15
to jenkins...@googlegroups.com
Hmmm..when issuing a multipart form submission,  i wouldn't expect the multipart parameters to become Linux shell variables unless the code receiving the http request took the parameters and made them so. Does your http endpoint do so ? Seems I am missing something.

Sent from my iPad

Greg Nifor

unread,
Aug 17, 2015, 4:11:03 PM8/17/15
to Jenkins Users
The job I'm triggering has two parameters, git and root. The curl sets those and I'm able to use those in my execute shell step.

Walter Kelt

unread,
Aug 17, 2015, 4:39:26 PM8/17/15
to jenkins...@googlegroups.com
Just looked at the Jenkins remote access api. Looks like file and parameters need to be passed into curl in a json format. Not sure what Jenkins version you are using, but you may want to check it out. 

If you are doing a parametrized build it looks to be a little more complicated and I don't see an example using -F

Sent from my iPad

Greg Nifor

unread,
Aug 17, 2015, 5:04:29 PM8/17/15
to Jenkins Users
Will do, thank you!

Daniel Beck

unread,
Aug 17, 2015, 5:42:58 PM8/17/15
to jenkins...@googlegroups.com
How to trigger a build with parameters is explained on the /job/JOBNAME/api URL in Jenkins -- the wiki page on the topic is a bit weird.
> To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/ED22D818-1ED7-4217-B112-D2AFC543847F%40comcast.net.

Greg Nifor

unread,
Aug 20, 2015, 12:23:53 PM8/20/15
to Jenkins Users, m...@beckweb.net
Update: Still doesn't work

json='{"parameter": [{"name": "text", "value": "AA"}, {"name": "file", "value": "file0"}]}'
url=<url>
curl $url -F file0=@<file_path> -F json="$json" -u <user>:<pass>

Greg Nifor

unread,
Aug 20, 2015, 12:28:57 PM8/20/15
to Jenkins Users, m...@beckweb.net
Caused by: java.lang.NullPointerException
    at hudson.model.FileParameterValue.&lt;init>(FileParameterValue.java:78)

Khai Do

unread,
Aug 21, 2015, 2:33:51 PM8/21/15
to Jenkins Users, m...@beckweb.net
If you don't mind using Python, both the python-jenkins and jenkinsapi packages can do this for you pretty easily.  Both are wrappers around the Jenkins REST api so basically exactly what you are trying to do with curl.

Richard Bywater

unread,
Aug 21, 2015, 7:27:06 PM8/21/15
to Jenkins Users, m...@beckweb.net

Or given that assuming you really want to use curl, presumably you could reference the code base of those projects to try and see how to do it :)

Richard.


Reply all
Reply to author
Forward
0 new messages