Issue
I have created a Scripted pipeline Jenkins job, in one of the stage I need to run a java file example:- java -jar accountrans.jar and I need to return the value to the variable.
stage('Account Process')
{
sh 'curl --noproxy "*" -X GET https://paraforce.com/artifactory/account/accountrans.jar -o accountrans.jar'
def acctval = sh script: "java -jar accountrans.jar . ", returnStatus: true
echo "Account Trans Value : " $acctval
}
I am getting error message java.lang.NullPointerException: Cannot get property 'java.lang.ClassCastException: body return value null is not boolean' on null object
When I ran the jar file from the command line I am able to view the return value.
Please help how to fix it.
Solution
I am not sure but try curly braces after sh.
stage('Account Process')
{
sh 'curl --noproxy "*" -X GET https://paraforce.com/artifactory/account/accountrans.jar -o accountrans.jar'
def acctval = sh {script: "java -jar accountrans.jar . ", returnStdout: true }
echo "Account Trans Value : " $acctval
}
Answered By - Aniket Kumar
Answer Checked By - Terry (JavaFixing Volunteer)