I\'m using Jenkins PowerShell plugin to build a project.
However, I found that Jenkins always considers my build successful no matter what I type inside Windows P
I want to add here that I just ran into a quirk: you must have the powershell script end with exit
and not return
.
My jenkins pipe looked like:
script {
result = powershell(returnStatus: true, script: '''...if(error condition) { return 1 }''')
if(result) { error }
}
I was using if(error condition) { return 1 }
and while the 1 was showing up as the return value in the jenkins console, it was not failing the build. When i used if(error condition) { exit 1 }
, the build failed as expected.
I think this is a helpful addition to this thread - the need to use exit
and not return
. But I don't understand this part: the pipe is checking for result
to be non-zero. What is the difference between exit
and return
in a powershell directive that makes if(result) { error }
not work as expected when using return
?