Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jmeter exit code in bash script always returns 0

Using jmeter in a bash script, how can I manage that it returns a non zero value if any assertion failed?

jmeter -n -t someFile.jmx
echo $?

# always returns 0, even if an assertion failed

I tried with a Bean Shell Assertion using the script:

if (ResponseCode.equals("200") == false) {
  System.exit(-1);
}

But this does not even return 0, it just kills the process (I guess?)

May anyone help me with this?

like image 680
RagnarLodbrok Avatar asked Apr 04 '18 13:04

RagnarLodbrok


People also ask

Should bash scripts end with exit 0?

Exit Status Each shell command returns an exit code when it terminates, either successfully or unsuccessfully. By convention, an exit code of zero indicates that the command completed successfully, and non-zero means that an error was encountered. The status code can be used to find out why the command failed.

How do I set an exit code in bash?

To set an exit code in a script use exit 0 where 0 is the number you want to return. In the following example a shell script exits with a 1 . This file is saved as exit.sh . Executing this script shows that the exit code is correctly set.

Which exit code indicates success for a bash script?

Exit status 0 It tells you that your latest command or script executed successfully. Success is relative because the exit code only informs you that the script or command executed fine, but the exit code doesn't tell you whether the information from it has any value.


2 Answers

Put the following code in JSR223 Element

System.exit(1);

It will return error level 1 which will be displayed in Linux when executing echo $?

like image 194
user7294900 Avatar answered Oct 03 '22 22:10

user7294900


In case you only care about jmeter returning exit code when errors are found, you can check the .log for lines with error afterwards:

test $(grep -c ERROR jmeter.log) -eq 0

If you call echo $?, you can see it returns 1 if errors are found and 0, if not.

like image 38
papierukartka Avatar answered Oct 03 '22 22:10

papierukartka