0

I have a console application that coded in C# that is used in my TFS release process, if this application encounters an error it will display the error then return a non-zero error code, looks like this:

try
{
    //Does stuff...

    return 0; //where 0 = success
}
catch (Exception ex)
{
    Console.WriteLine("Error in Main: " + ex.Message + "\n" + ex.StackTrace);

    for (int i = 0; i < args.Length; i++)
    {
        Console.WriteLine("Value in args[" + i + "]: " + (i == 3 ? "**********" : args[i]));
    }

    //Return error state
    return 1;
}

It is invoked by a PowerShell script in TFS that looks like this:

# (Does some parsing stuff...)
echo $abc
Start-Process -FilePath $abc-ArgumentList $arguments -NoNewWindow -PassThru -Wait

Now my problem is that sometime the console app fails, it prints the error and exits correctly, but for some reason TFS doesn't don't detect this and considers the step "done":

enter image description here

enter image description here

I'm not really sure what I'm missing, what does my PowerShell script/application need to do to indicate the the TFS that a failure has occurred? I thought the "PassThrough" tag in PowerShell should route the error code up, is that not correct?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
David Rogers
  • 2,601
  • 4
  • 39
  • 84

1 Answers1

0

Looks like I was confused about the PowerShell part of the equation, I need to capture the error and pass it up to TFS. I found the following solution helpful. Also solved here...

I did something like this:

$Output = Start-Process XYZ...

If($Output.Exitcode -ne 0)
{
     Throw "Errorlevel $($Output.ExitCode)"
}
David Rogers
  • 2,601
  • 4
  • 39
  • 84