1

I am running a script on a remote server (windows) using Jenkins:

Invoke-Command -ComputerName myserver -ScriptBlock { D:\DeployScript\myscript.bat } -credential $Cred -ErrorAction Stop

inside this "myscript.bat" i running a psexec command:

psexec -i -h -u myserver\Administrator -p mypassword {mycommands}

how can i tell Jenkins to stop if an error occur on "myscript.bat"

(i must using Psexec because the script require interactive desktop)

Thanks!

abovebeyond15
  • 105
  • 1
  • 9

1 Answers1

2

In powershell you can get the exit code of the last command using the automatic variable $lastexitcode, so try something like this:

if ($lastexitcode -ne 0) { exit 1 }

or even better:

exit $lastexitcode
4c74356b41
  • 69,186
  • 6
  • 100
  • 141
  • Thanks ! i will try it.Does the powershell script will know that the psexec threw an error? i dont need to :forward" it? – abovebeyond15 Apr 26 '17 at 09:39
  • probably this will help http://stackoverflow.com/questions/334879/how-do-i-get-the-application-exit-code-from-a-windows-command-line @abovebeyond15 – 4c74356b41 Apr 26 '17 at 09:58