I have a Groovy script that runs a separate Powershell script as part of a Jenkins pipeline. The Powershell script returns a value (int) and I intend to use that value in the Groovy script by assigning it to a variable but the groovy variable is always evaluated to null. Code below, edited for brevity.
Powershell Script
#Some actions...
$foo = 0
return $foo
Returns (when run manually in Powershell):
0
Groovy Script
stage('StageX'){
//Some actions...
def return_val = powershell "Path\\to\\script\\someScript.ps1"
echo return_val
if (return_val == 0){
//Do things...
}
}
Returns:
null
I know that the script actually runs as it performs other actions that are apparent when the Groovy script runs, I just can't seem to get Groovy to pick up the return value of the Powershell script.
What is the best way to do this?