Jenkins Pipeline terminated after sh returnStdout exit code nonzero

706 views Asked by At

I have a groovy function to fetch the code coverage after apex run test execution.

def jsonResult = sh returnStdout: true, script: "sfdx force:apex:test:report --testrunid ${testRunId} --resultformat json --targetusername ${username} --codecoverage"
def coverageResult = readJSON text: jsonResult?.trim() 

String coverageOutput = coverageResult.result.summary.testRunCoverage;
Double coverageAsDouble = Double.parseDouble(coverageOutput.replace("%",""));
   
if(coverageAsDouble >= 75) {
   echo "Succesfully run test!"
}else {
   error "Code coverage less than expected: ${ coverageOutput }"
}

If one or more test classes failed, it will return exit code 100 and the step failed.

ERROR:hudson.AbortException: script returned exit code 100

Is there any way to get the JSON response from sh by ignoring the exit code to process the next step?

0

There are 0 answers