TeamCity build error due to exits of child processes with non-zero exit code

I have a TeamCity (8.1) build project that works fine in most cases. Part of my MSBuild script is that the embedded executable needs to be code signed, and there the build sometimes doesn't work.

<Target Name="AfterBuild">
   <Exec Command="sign.exe /D &quot;$(OutputName)&quot; &quot;$(TargetPath)&quot; &quot;certificate.pfx&quot; password" />
</Target>

      

sign.exe

is a command line helper tool that internally calls signtool.exe

from the Microsoft Windows SDK (it determines which version is installed) using hardcoded timestamp servers on iteration, as sometimes a timestamp server is not reachable.

foreach (var tsServer in TimestampServer)
{
    var p = new Process
    {
        StartInfo =
        {
            UseShellExecute = false,
            RedirectStandardOutput = true,
            RedirectStandardError = true,
            FileName = signtool,
            Arguments = String.Format("sign /f \"{0}\" /p {1} {4} /d \"{3}\" \"{2}\"", cert, pass, file, description ?? Path.GetFileName(file), tsServer)
        }
    };
    p.Start();
    p.WaitForExit();

    if (p.ExitCode == 0)
    {
        // signing succeeded
        Environment.Exit(0);
    }
}
// if all failed issue a nonzero exit code
Environment.Exit(-1);

      

My custom sign.exe

only returns an unnecessary exit code if all timestamp servers crash (change: this hasn't happened yet). But TeamCity notes that the build failed because it detects that my child process sign.exe

exited with a non-zero exit code (edit :), even though a later call to signtool.exe was successful and sign.exe returns zero output code.

I know of an option to ignore non-zero exit codes, but I want to ignore the exit codes of the child processes of my sign tool (change), not the exit code of my sign.exe, because my tool was written exactly to solve this problem.

Is there a way in TeamCity to solve this problem, or do I have the option to modify my own command line tool in C # to avoid propagating exit codes of child processes?

+3


source to share


1 answer


I know this option to ignore non-zero exit codes, but I just want to ignore the exit codes of my sign tool's child processes.

Are you sure it's safe? Is it ok in your environment if the signing fails and the assembly is still created?

Is there a way in TeamCity to solve this problem, or do I have the option to modify my own command line tool in C # to avoid propagating exit codes of child processes?



I'm not sure about the options in TeamCity, but since sign.exe is under your control, you can always return 0 to it regardless of whether the child process exited.

If all temporary servers fail from time to time, have you investigated the potential causes? Perhaps a temporary internet disruption at your end? You can try pinging something very reliable outside of your network from sign.exe after all the time servers have passed to see if there is a general internet violation.

It may be worth repeating the entire cycle foreach

one or more times after the delay, so that any condition leads to an incorrect spontaneous outcome.

0


source







All Articles