diff --git a/Public/Src/Tools/AdoBuildRunner/Program.cs b/Public/Src/Tools/AdoBuildRunner/Program.cs index 238ad8e576..6a2c806eb2 100644 --- a/Public/Src/Tools/AdoBuildRunner/Program.cs +++ b/Public/Src/Tools/AdoBuildRunner/Program.cs @@ -119,6 +119,14 @@ public static async Task Main(string[] args) $"and to communicate the build information to the worker pipeline"); } + var attemptNumber = Environment.GetEnvironmentVariable(Constants.JobAttemptVariableName) ?? "1"; + if (int.TryParse(attemptNumber, out var jobAttempt) && jobAttempt > 1) + { + // The job was rerun. Let's change the invocation key to reflect that + // so we don't conflict with the first run. + invocationKey += $"__jobretry_{jobAttempt}"; + } + var buildContext = await api.GetBuildContextAsync(invocationKey); var buildManager = new WorkerPipelineBuildManager(api, executor, buildContext, args, logger); return await buildManager.BuildAsync(isOrchestrator);