Issue
I'd like to set the env variable based on the execute result of bat. When compile.bat
return 1
, how to set env.BuildResult
as FAILURE
?
node("test")
{
env.BuildResult='SUCCESS'
stage('Compile')
{
bat'''
call compile.bat
if %ERRORLEVEL% NEQ 0 SET BuildResult='FAILURE'
'''
}
stage('Post')
{
bat'''
echo %BuildResult%
''''
}
}
Solution
Move it to the level of pipeline
def res = bat script:'call compile.bat', returnStatus:true
if( res!= 0 ) env.BuildResult = 'failure'
Answered By - daggett
Answer Checked By - Senaida (JavaFixing Volunteer)