I have a TeamCity (8.1) build project which runs fine most of the time. A part of my MSBuild script is, that the built executable should be code-signed, and there the build fails sometimes.
<Target Name="AfterBuild">
<Exec Command="sign.exe /D "$(OutputName)" "$(TargetPath)" "certificate.pfx" password" />
</Target>
The sign.exe
is a helper command line tool, which internally calls the signtool.exe
from the Microsoft Windows SDK (it detects which version is installed) using hard coded timestamp servers in an iteration, because 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 a nonzero exit code if signing with all timestamp servers failed (edit: which not happened yet). But TeamCity marks the build as failed, because it detects, that a child process of my sign.exe
exited with a nonzero exit code (edit:) even if a later call to signtool.exe was successful and sign.exe returns a zero exit code.
I know the option, to ignore nonzero exit codes, but I only want to ignore the exit codes of the child processes of my sign tool (edit) not the exit code of my sign.exe, because my tool was written exactly for the purpose to handle this issue.
Is there a way within TeamCity to handle this issue, or do I have an option to modify my custom C# command line tool to not propagate the exit codes of the child processes?