Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-63547

Write response to file before checking response status code

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Minor Minor
    • http-request-plugin
    • None

      Currently, the order of execution when processing an HTTP response is:

      • Log the body, if configured.
      • Check the response code and fail if it isn't in the expected range.
      • Write the response to a file.

      The result of this is that consoleLogResponseBody and outputFile aren't equivalent: the former happens regardless of response status but the latter only happens if the status is in the expected range.

      This is the code in question:

      HttpRequestExecution.java
      	private void processResponse(ResponseContentSupplier response) throws IOException, InterruptedException {
      		//logs
      		if (consoleLogResponseBody) {
      			logger().println("Response: \n" + response.getContent());
      		}
      
      		//validate status code
      		responseCodeIsValid(response);
      
      		//validate content
      		if (!validResponseContent.isEmpty()) {
      			if (!response.getContent().contains(validResponseContent)) {
      				throw new AbortException("Fail: Response doesn't contain expected content '" + validResponseContent + "'");
      			}
      		}
      
      		//save file
      		...
      

      This ticket proposes changing this so that the response content is always written to a file, if configured, regardless of the response status.

      My use case is uploading a large amount of data to Elasticsearch. The response is correspondingly large so I don't want to log it to the console, plus it's JSON so I'd prefer to write it to a file for easier querying in any case. So I set outputFile and archive that file, but if my request fails the file isn't written and I can't diagnose the issue. Instead I'm going to have to change my plugin call to allow any HTTP status and then write the response body to a file before manually checking the status.

            janario Janario Oliveira
            allanlewis Allan Lewis
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated: