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

    The raw body of the request.

    Parameters will be resolved.

    • Type: String
  • 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 (optional)
    Specify a timeout value in seconds (default is 0 which implies no timeout).
    • Type: int
  • uploadFile (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.
    • Type: String
  • useNtlm (optional)
    • Type: boolean
  • useSystemProperties (optional)
    Use system properties to configure the client.
    • Type: boolean
  • validResponseCodes (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".
    • Type: String
  • validResponseContent (optional)
    If set response must contain this string to mark an execution as success.
    • Type: String
  • wrapAsMultipart (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.
    • Type: boolean

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.