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.
CodePudding user response:
I'm assuming your program outputs something to the Stdout. But you are trying to retreive the status code. Instead of returnStatus
try returnStdout
.
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
}
CodePudding user response:
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
}