From 17a36d58bedf6626c182cd539cf20ecd9ee6f60e Mon Sep 17 00:00:00 2001 From: Lokesh Gopu Date: Tue, 19 May 2020 17:46:20 -0400 Subject: [PATCH] Max attempts while adding runner --- src/Runner.Listener/Configuration/ConfigurationManager.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Runner.Listener/Configuration/ConfigurationManager.cs b/src/Runner.Listener/Configuration/ConfigurationManager.cs index 289ccaa1a..464818b3c 100644 --- a/src/Runner.Listener/Configuration/ConfigurationManager.cs +++ b/src/Runner.Listener/Configuration/ConfigurationManager.cs @@ -160,8 +160,11 @@ namespace GitHub.Runner.Listener.Configuration } TaskAgent agent; + int attemptCount = 5; + while (true) { + attemptCount--; runnerSettings.AgentName = command.GetRunnerName(); _term.WriteLine(); @@ -192,10 +195,10 @@ namespace GitHub.Runner.Listener.Configuration _term.WriteError("Failed to replace the runner. Try again or ctrl-c to quit"); } } - else if (command.Unattended) + else if (command.Unattended || attemptCount <= 0) { // if not replace and it is unattended config. - throw new TaskAgentExistsException($"Pool {runnerSettings.PoolId} already contains a runner with name {runnerSettings.AgentName}."); + throw new TaskAgentExistsException($"A runner already exists with the name {runnerSettings.AgentName}."); } } else @@ -216,6 +219,7 @@ namespace GitHub.Runner.Listener.Configuration } } } + // Add Agent Id to settings runnerSettings.AgentId = agent.Id;