0

I made a new extension for TFS (Build Step), that's running a powershell script.

How can I exit the script that will make this build step to failed? (red "X" in the TFS steps). I tried exit code 99, when getting an exception but it's still green.

Should I throw exception without catching it from the power shell script?

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
Aviram Fireberger
  • 3,910
  • 5
  • 50
  • 69
  • 1
    Am no expert on this, but in examples I see `exit 1` being used, e.g. here: https://www.visualstudio.com/en-us/docs/build/scripts/ – Peter B Feb 06 '17 at 08:18
  • Thanks Found that by adding "**Write-Error**" print in powershell it will mark the build step as failed, regardless the exit code. – Aviram Fireberger Feb 06 '17 at 08:36
  • My experience with TFS 2017 build extensions is that Write-Error also terminates the step. That is not consistent with normal powershell function. My extension expects continuation, so I am going to try Write-Warning. – Layne Carder Jul 17 '18 at 15:32

2 Answers2

1

Found that by adding "Write-Error" print in powershell it will mark the build step as failed, regardless the exit code:

Write-Error "My fail reason."
Aviram Fireberger
  • 3,910
  • 5
  • 50
  • 69
  • This works, you can use `Write-Warning`, or `Write-Error` if you want to log errors, if you want to terminate the build use `throw`. – Daniel Morritt Feb 06 '17 at 12:43
0

Possible duplicate with this question: How to fail the build from a PowerShell task in TFS 2015

Just using below simple script

 Write-Error ("Some error")
 exit 1

Moreover, you should also be able to return warnings and errors from your script using logging commands.

Community
  • 1
  • 1
PatrickLu-MSFT
  • 49,478
  • 5
  • 35
  • 62