Detect error and exit

Hi,

I am using Jenkins and have integrated JMeter for testing. JMeter is generating a file with results properly using shell script. I have to validate the results and exit the shell with non-zero so my jenkins job gets failed. I tried multiple ways to grep the output file and read the results in an array but its not working.

I gave a grep command, but got to remove '(' and ')' as shell is not accepting so this is not converting to array

Error :

array=($(grep -oP '(?<=error>)[^<]+' "TestCases/results.jtl") )

accepted by shell:

array=$(grep -oP '(?<=error>)[^<]+' "TestCases/results.jtl") 

Below is the file , using shell script I have to exit when 'error' count with value true is greater than 1.

results.jtl File :

<testResults version="1.2">
<httpSample t="73" it="0" lt="0" ct="65" ts="1486696391218" s="false" lb="LoopbackRequest" rc="Non HTTP response code: org.apache.http.NoHttpResponseException" rm="Non HTTP response message: 192.168.99.100:2011 failed to respond" tn="DPIntegration_Testing 1-1" dt="text" by="2249" sby="0" ng="1" na="1">
  <assertionResult>
    <name>XPath Assertion</name>
    <failure>false</failure>
    <error>true</error>
    <failureMessage>SAXException: Content is not allowed in prolog.</failureMessage>
  </assertionResult>
</httpSample>

<httpSample t="70" it="0" lt="0" ct="63" ts="1486696392639" s="false" lb="LoopbackRequest" rc="Non HTTP response code: org.apache.http.NoHttpResponseException" rm="Non HTTP response message: 192.168.99.100:2011 failed to respond" tn="DPIntegration_Testing 1-1" dt="text" by="2249" sby="0" ng="1" na="1">
  <assertionResult>
    <name>XPath Assertion</name>
    <failure>false</failure>
    <error>true</error>
    <failureMessage>SAXException: Content is not allowed in prolog.</failureMessage>
  </assertionResult>
</httpSample>

</testResults>

Can someone please help me with this ?

Thanks.

Hi,

  • Does it not work from the command line?
  • What is the exact error message that you are getting?
  • What shell are you using?
  • What OS and version?
  • Have you tried putting a space between ( and $( ?, so ( $( ?
  • Did you also get the same error message with your input sample?
  • Tried to reproduce, but could not with reproduce error. It resulted in an 2-element array, each element with the value "true"..

Thank you so much for your questions :slight_smile: . I have started looking for what shell 'Jenkins' tool is using, I couldn't identify but changed it to bash and got it working now.

Thanks again
Sitaram.

1 Like