How can I POST data to a remote service in Jenkins pipeline/workflow?

2,965 views
Skip to first unread message

Scott Richmond

unread,
Jan 31, 2016, 12:20:46 PM1/31/16
to Jenkins Users
I require the ability to HTTP POST data to a remote service via some kind of REST client. This will be done on Windows agents, so the native curl support in sh is not suitable. Is there any way to do this in the groovy script?

Craig Rodrigues

unread,
Jan 31, 2016, 5:08:42 PM1/31/16
to Jenkins Users, s.t.ri...@gmail.com
Hi,

curl is one way of calling a REST API from the command-line, but it
is not the only way.  You can create a Jenkins job, and
use many languages to call REST API's inside these jobs,
even on Windows.

For example, if you want to use groovy, using the HTTPBuilder library
is one way to do it:
https://www.google.com/search?q=groovy+rest+api

If you want to use C#, you can look at using the restsharp library:
https://www.google.com/search?q=c+sharp+rest+api

--
Craig

Scott Richmond

unread,
Jan 31, 2016, 5:49:11 PM1/31/16
to Craig Rodrigues, Jenkins Users

The httpbuilder library doesn’t appear to work as it’s not available. Do I have to add it to the default libraries or something?

 

Sent from Outlook Mail for Windows 10 phone

Michael Neale

unread,
Jan 31, 2016, 7:40:36 PM1/31/16
to Jenkins Users, rod...@freebsd.org
Do you have access to powershell? 


(calling from pipeline script should be fine, but I can't find an example of how best to do it. Some comment that blocking for an external thing is not ideal.. vs a shell script which will do the right thing if you have it available). 

https://www.cloudbees.com/blog/jenkins-workflow-creating-class-wrap-access-secured-http-endpoint shows an extension that calls a remote jenkins with form auth, which isn't quite what you want, but it is calling https from within a workflow scripting using the global library, so you may be able to follow along but do your own. 

Craig Rodrigues

unread,
Feb 1, 2016, 5:49:24 PM2/1/16
to Scott Richmond, Jenkins Users
Yes, you would need to install HTTPBuilder.

You can decide if you want to install additional groovy libraries,
or if you prefer switch to a scripting language of your choice, which
you can call from inside a Jenkins job in order to access a REST service.
--
Craig

Scott Richmond

unread,
Feb 1, 2016, 6:18:12 PM2/1/16
to Craig Rodrigues, Jenkins Users

How does one install httpbuilder a part of the Jenkins client? I’ve found very little instruction on this.

Andrew Bayer

unread,
Feb 2, 2016, 12:26:12 PM2/2/16
to jenkins...@googlegroups.com, Craig Rodrigues
So using HTTPBuilder from Pipeline is not a good idea - see https://issues.jenkins-ci.org/browse/JENKINS-26192 - there's work in progress on https://github.com/jenkinsci/http-request-plugin/pull/13 for adding Pipeline support to the http-request-plugin, which is probably the direction you'd want to go.

A.

--
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/-2616028336673081203%40unknownmsgid.

For more options, visit https://groups.google.com/d/optout.

James Nord

unread,
Feb 2, 2016, 4:04:02 PM2/2/16
to Jenkins Users, rod...@freebsd.org

Curl is just a program that most Unix like OSes happen to have installed by default.
There are native binaries available for windows (both 32 and 64bit) that you could install on your slaves (erm agents) if you already have the curl commands written.
So you can call it on windows using the 'bat' pipeline step.

/James
Reply all
Reply to author
Forward
0 new messages