In Jenkins, how can I configure the build to fail when error codes fall within the range of 206 to 599 in JMeter performance tests. i want the build to fail when any API from Jmeter test fails (throws error ) any http value from 206 to 599 build should fail

1

There are 1 best solutions below

0
Dmitri T On

I would recommend the following approach:

  1. Add JSR223 Assertion as a child of the request which response code you want to validate

  2. Put the following code into "Script" area:

    def status = prev.getResponseCode() as int
    
    if (status >= 206 && status <= 599) {
        assertionResult.setFailure(true)
        assertionResult.setFailureMessage("Unexpected status code: " + status)
    }
    

    This will mark the sampler as failed if response code within the given range.

  3. For failing the Jenkins build you can use Jenkins Performance Plugin which can mark the build as failed if response code falls into unexpected range.