Link Search Menu Expand Document

HTTP requests from Jenkins pipelines

This post provides a summary of the possibilities to perform HTTP requests from a Jenkins pipeline.


There are at least the following possibilities

  • Just doing a curl in a shell
  • Using Groovy URL object
  • Using plain old Java networking methods
  • Using a Jenkins plugin like http_request

Also security wise to properly handle the Jenkins sandboxing/script approval the call might want to be done

  • inline (with code inside the pipeline)
  • in a global shared libary

Sandboxing and Script Approval

In a properly configured Jenkins setup you usually have explicit script approval active and to use non-default libraries you need to extend the signature whitelist. Alternatively you can provide the required HTTP request functionality via a plugin or a global shared library, both of which are not subject to the script approval/signature whitelisting.

Mapping the security configuration impact gives us this matrix:

VariantImpact when used inlineImpact when used in plugin/global shared library
Groovy URLsignature approval needednone
Java networkingsignature approval needednone

While using curl or a plugin have no security impact on pipeline development, they both have to be provided in terms of setup: curl needs to be installed on Jenkins agents and the plugin has to be installed and maintained in Jenkins setup, both of which is usually a ITOps/DevOps task and if you are a pipeline developer might not be an option.

In terms of actively and continuously developing required functionality I believe a global shared library is the way to go no matter your role (Dev, DevOps, Build Engineer, IT Ops). This is both because it can be easily configured and development can happen by testing pipelines against new feature branches of the library.

Examples Snippets

Below you find example snippets for the HTTP request mechanism mentioned above.


 sh 'curl'



 def get = new URL("").openConnection();
 def getRC = get.getResponseCode();
 if(getRC.equals(200)) {

Using Java base libraries

Copied from


def sendPostRequest(urlString, paramString) {
    def url = new URL(urlString)
    def conn = url.openConnection()
    def writer = new OutputStreamWriter(conn.getOutputStream())

    String line
    def reader = new BufferedReader(new InputStreamReader(conn.getInputStream()))
    while ((line = reader.readLine()) != null) {
      println line

sendPostRequest("", "")

Using the http_request plugin

 def response = httpRequest 'http://localhost:8080/jenkins/api/json?pretty=true'
 println("Status: "+response.status)
 println("Content: "+response.content)