From 2baa9d7f13655485b25ade83a9bbd62b6d5af968 Mon Sep 17 00:00:00 2001 From: surajitshil-03 Date: Wed, 10 Sep 2025 13:31:15 +0000 Subject: [PATCH 1/2] Adding url parameter to remove agent --- src/Agent.Listener/CommandLine/RemoveAgent.cs | 2 ++ src/Agent.Listener/CommandSettings.cs | 9 ++++++--- src/Agent.Listener/Configuration/ConfigurationManager.cs | 9 +++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Agent.Listener/CommandLine/RemoveAgent.cs b/src/Agent.Listener/CommandLine/RemoveAgent.cs index 5b62d3e3a0..433f599f07 100644 --- a/src/Agent.Listener/CommandLine/RemoveAgent.cs +++ b/src/Agent.Listener/CommandLine/RemoveAgent.cs @@ -6,5 +6,7 @@ namespace Agent.Listener.CommandLine [Verb(Constants.Agent.CommandLine.Commands.Remove)] public class RemoveAgent : ConfigureOrRemoveBase { + [Option(Constants.Agent.CommandLine.Args.Url)] + public string Url { get; set; } } } diff --git a/src/Agent.Listener/CommandSettings.cs b/src/Agent.Listener/CommandSettings.cs index c133304a87..4819e65151 100644 --- a/src/Agent.Listener/CommandSettings.cs +++ b/src/Agent.Listener/CommandSettings.cs @@ -318,15 +318,18 @@ public string GetToken() public string GetUrl(bool suppressPromptIfEmpty = false) { + // Check for URL from either Configure or Remove commands + string urlValue = Configure?.Url ?? Remove?.Url; + // Note, GetArg does not consume the arg (like GetArgOrPrompt does). if (suppressPromptIfEmpty && - string.IsNullOrEmpty(GetArg(Configure?.Url, Constants.Agent.CommandLine.Args.Url))) + string.IsNullOrEmpty(GetArg(urlValue, Constants.Agent.CommandLine.Args.Url))) { return string.Empty; } - + return GetArgOrPrompt( - argValue: Configure?.Url, + argValue: urlValue, name: Constants.Agent.CommandLine.Args.Url, description: StringUtil.Loc("ServerUrl"), defaultValue: string.Empty, diff --git a/src/Agent.Listener/Configuration/ConfigurationManager.cs b/src/Agent.Listener/Configuration/ConfigurationManager.cs index 45e60a1542..07c29170de 100644 --- a/src/Agent.Listener/Configuration/ConfigurationManager.cs +++ b/src/Agent.Listener/Configuration/ConfigurationManager.cs @@ -576,6 +576,7 @@ public async Task UnconfigureAsync(CommandSettings command) if (isConfigured && hasCredentials) { AgentSettings settings = _store.GetSettings(); + var credentialManager = HostContext.GetService(); // Get the credentials @@ -602,6 +603,14 @@ public async Task UnconfigureAsync(CommandSettings command) IConfigurationProvider agentProvider = (extensionManager.GetExtensions()).FirstOrDefault(x => x.ConfigurationProviderType == agentType); ArgUtil.NotNull(agentProvider, agentType); + // If a URL is provided via command line, override the stored ServerUrl BEFORE checking if hosted + string commandUrl = command.GetUrl(); + if (!string.IsNullOrEmpty(commandUrl)) + { + Trace.Info($"Overriding stored ServerUrl '{settings.ServerUrl}' with command line URL '{commandUrl}' for removal operation"); + settings.ServerUrl = commandUrl; + } + bool isHostedServer = await CheckIsHostedServer(agentProvider, settings, credProvider, agentCertManager.SkipServerCertificateValidation); VssCredentials creds = credProvider.GetVssCredentials(HostContext); From 7e8b0aca597c8f17f0869b3c597fa11f9f039f67 Mon Sep 17 00:00:00 2001 From: surajitshil-03 Date: Thu, 11 Sep 2025 05:54:27 +0000 Subject: [PATCH 2/2] Passing suppressPromptIfEmpty as a paramter with value true --- src/Agent.Listener/Configuration/ConfigurationManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Agent.Listener/Configuration/ConfigurationManager.cs b/src/Agent.Listener/Configuration/ConfigurationManager.cs index 07c29170de..8ef2bbec70 100644 --- a/src/Agent.Listener/Configuration/ConfigurationManager.cs +++ b/src/Agent.Listener/Configuration/ConfigurationManager.cs @@ -604,7 +604,7 @@ public async Task UnconfigureAsync(CommandSettings command) ArgUtil.NotNull(agentProvider, agentType); // If a URL is provided via command line, override the stored ServerUrl BEFORE checking if hosted - string commandUrl = command.GetUrl(); + string commandUrl = command.GetUrl(suppressPromptIfEmpty: true); if (!string.IsNullOrEmpty(commandUrl)) { Trace.Info($"Overriding stored ServerUrl '{settings.ServerUrl}' with command line URL '{commandUrl}' for removal operation");