The following plugin provides functionality available through Pipeline-compatible steps. Read more about how to integrate steps into your Pipeline in the Steps section of the Pipeline Syntax page.

For a list of other such plugins, see the Pipeline Steps Reference page.

HTTP Request Plugin

httpRequest: Perform an HTTP Request and return a response object

Performs an HTTP request, and returns a response object.

Usage example:

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

If Jenkins restarts after the HTTP request is made, but before the HTTP response is received, the HTTP request fails.

validResponseCodes is a comma-separated string of single values or from:to ranges. For example '200' to accept only 200 or '201,301:303' to accept 201 as well as the range from 301 to 303.

The methods of the response object are:

  • String getContent(): The HTTP Response entity. This means the text of the response without the headers. If the response does not contain an entity, getContent() returns null.
  • int getStatus(): The HTTP status code.

  • url : String
    Specify an URL to be requested.
  • acceptType (optional)
    Add Accept: foo HTTP request header where foo is the HTTP content type to accept.
    • Values: NOT_SET, TEXT_HTML, TEXT_PLAIN, APPLICATION_FORM, APPLICATION_FORM_DATA, APPLICATION_JSON, APPLICATION_JSON_UTF8, APPLICATION_TAR, APPLICATION_ZIP, APPLICATION_OCTETSTREAM
  • authentication : String (optional)
    Authentication that will be used before this request. Authentications are created in global configuration under a key name that is selected here.
  • consoleLogResponseBody : boolean (optional)
    This allows to turn off writing the response body to the log.
  • contentType (optional)
    Add Content-Type: foo HTTP request header where foo is the HTTP content type the request is using.
    • Values: NOT_SET, TEXT_HTML, TEXT_PLAIN, APPLICATION_FORM, APPLICATION_FORM_DATA, APPLICATION_JSON, APPLICATION_JSON_UTF8, APPLICATION_TAR, APPLICATION_ZIP, APPLICATION_OCTETSTREAM
  • customHeaders (optional)
      Array / List of Nested Object
    • name : String
    • value : String
    • maskValue : boolean
  • formData (optional)
      Array / List of Nested Object
    • uploadFile : String
    • name : String
    • fileName : String
    • contentType : String
    • body : String
  • httpMode (optional)
    The HTTP mode of the request such as 'GET' or 'POST'.
    • Values: GET, HEAD, POST, PUT, DELETE, OPTIONS, PATCH, MKCOL
  • httpProxy : String (optional)
    Use a proxy to process the HTTP request. Example: http://mycorpproxy:80
  • ignoreSslErrors : boolean (optional)
    If set to true, a request with HTTPS will trust in the certificate even when it is invalid or expired.
  • multipartName : String (optional)
    Multipart entity name used in the Content-Disposition header in conjunction with the upload file path.
  • outputFile : String (optional)
    Name of the file in which to write response data.
  • proxyAuthentication : String (optional)
  • quiet : boolean (optional)
    This allows to turn off all logging output.
  • requestBody : String (optional)

    The raw body of the request.

    Parameters will be resolved.

  • responseHandle (optional)
    How response should be handled.
    STRING(default) will transform the response in string.
    NONE will not read the response content and will close the response after the job execution.
    LEAVE_OPEN will not read the response content but leaves an open input stream to be read outside the job execution. Using LEAVE_OPEN it is your responsibility to close it after use. 'response.close();'
    • Values: NONE, LEAVE_OPEN, STRING
  • timeout : int (optional)
    Specify a timeout value in seconds (default is 0 which implies no timeout).
  • uploadFile : String (optional)
    Path to the upload file, relative to build workspace or absolute path.

    Can be used to upload a file as multipart/form-data POST request. The according content type should be set above, defaults to application/octet-stream otherwise.
  • useNtlm : boolean (optional)
  • useSystemProperties : boolean (optional)
    Use system properties to configure the client.
  • validResponseCodes : String (optional)
    Configure response code to mark an execution as success.
    You can configure simple code such as "200" or multiple codes separeted by comma(',') e.g. "200,404,500"
    Interval of codes should be in format From:To e.g. "100:399".
    The default (as if empty) is to fail to 4xx and 5xx. That means success from 100 to 399 "100:399".
    To ignore any response code use "100:599".
  • validResponseContent : String (optional)
    If set response must contain this string to mark an execution as success.
  • wrapAsMultipart : boolean (optional)
    If set to false an upload file will be set directly as body of the request and will not be wrapped as multipart/form-data.

Was this page helpful?

Please submit your feedback about this page through this quick form.

Alternatively, if you don't wish to complete the quick form, you can simply indicate if you found this page helpful?

    


See existing feedback here.