Re-try failed build that is part of a build chain

Is there a built-in way in TeamCity to retry a specific build in a build chain, up to a maximum number of times, and as long as it succeeds at least once, consider it a success for any downstream build configs?

ie, say I have Build A, which sometimes randomly fails, and Build B, which has Build A as a snapshot dependency.

If Build A fails, I'd like to re-run it up to a maximum of 3 times... and as long as it succeeds at least once, launch Build A.  If it fails 3 times in a row, it will "overall" be marked as a failure in the build chain, and Build B will not start.

I know that there are "Retry Build Triggers":

https://www.jetbrains.com/help/teamcity/configuring-retry-build-trigger.html

...but if I'm reading that right, then it will simply launch a new Build A, but there won't be a new Build B which depends on it.

Note also that I don't want to simply set a retry trigger on Build B, because (assuming Build A worked), Build B is very reliable, and any failure in Build B should ALWAYS be considered a failure immediately.

Is there any way built-into TeamCity to accomplish this? The only way I can think of to get the result I want is to add custom scripting code to either:

  • Implement the retry logic myself - ie, make a new top-level script which runs build B in a subprocess, and monitor it and retry up to 3 times myself.  Not ideal because this requires re-implementing all the failure and hang detection logic that TeamCity normally handles.
  • Create a build chain that is, instead of just A > B, 
    A => B
    is
    A1 => A2 => A3 => B

    Where A2 and A3 have custom scripts that first make use of the TeamCity API to see if the upstream job succeeded, and if so, do nothing and succeed; and if it failed, re-run job A.

2

Please sign in to leave a comment.