diff --git a/src/Agent.Worker/Handlers/LegacyPowerShellHandler.cs b/src/Agent.Worker/Handlers/LegacyPowerShellHandler.cs index 8c8868c346..211a1b6208 100644 --- a/src/Agent.Worker/Handlers/LegacyPowerShellHandler.cs +++ b/src/Agent.Worker/Handlers/LegacyPowerShellHandler.cs @@ -209,7 +209,11 @@ public async Task RunAsync() AddPrependPathToEnvironment(); // Add proxy setting to LegacyVSTSPowerShellHost.exe.config - AddProxySetting(); + var agentProxy = HostContext.GetService(); + if (!string.IsNullOrEmpty(agentProxy.ProxyAddress)) + { + AddProxySetting(agentProxy); + } // Invoke the process. using (var processInvoker = HostContext.CreateService()) @@ -376,7 +380,7 @@ protected virtual void AddLegacyHostEnvironmentVariables(string scriptFile, stri } } - private void AddProxySetting() + private void AddProxySetting(IVstsAgentWebProxy agentProxy) { string appConfig = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.LegacyPSHost), _appConfigFileName); ArgUtil.File(appConfig, _appConfigFileName); @@ -395,68 +399,64 @@ private void AddProxySetting() File.Copy(appConfigRestore, appConfig); } - var agentProxy = HostContext.GetService(); - if (!string.IsNullOrEmpty(agentProxy.ProxyAddress)) + XmlDocument psHostAppConfig = new XmlDocument(); + using (var appConfigStream = new FileStream(appConfig, FileMode.Open, FileAccess.Read)) { - XmlDocument psHostAppConfig = new XmlDocument(); - using (var appConfigStream = new FileStream(appConfig, FileMode.Open, FileAccess.Read)) - { - psHostAppConfig.Load(appConfigStream); - } + psHostAppConfig.Load(appConfigStream); + } - var configuration = psHostAppConfig.SelectSingleNode("configuration"); - ArgUtil.NotNull(configuration, "configuration"); + var configuration = psHostAppConfig.SelectSingleNode("configuration"); + ArgUtil.NotNull(configuration, "configuration"); - var exist_defaultProxy = psHostAppConfig.SelectSingleNode("configuration/system.net/defaultProxy"); - if (exist_defaultProxy == null) + var exist_defaultProxy = psHostAppConfig.SelectSingleNode("configuration/system.net/defaultProxy"); + if (exist_defaultProxy == null) + { + var system_net = psHostAppConfig.SelectSingleNode("configuration/system.net"); + if (system_net == null) { - var system_net = psHostAppConfig.SelectSingleNode("configuration/system.net"); - if (system_net == null) - { - Trace.Verbose("Create system.net section in appconfg."); - system_net = psHostAppConfig.CreateElement("system.net"); - } + Trace.Verbose("Create system.net section in appconfg."); + system_net = psHostAppConfig.CreateElement("system.net"); + } - Trace.Verbose("Create defaultProxy section in appconfg."); - var defaultProxy = psHostAppConfig.CreateElement("defaultProxy"); - defaultProxy.SetAttribute("useDefaultCredentials", "true"); + Trace.Verbose("Create defaultProxy section in appconfg."); + var defaultProxy = psHostAppConfig.CreateElement("defaultProxy"); + defaultProxy.SetAttribute("useDefaultCredentials", "true"); - Trace.Verbose("Create proxy section in appconfg."); - var proxy = psHostAppConfig.CreateElement("proxy"); - proxy.SetAttribute("proxyaddress", agentProxy.ProxyAddress); - proxy.SetAttribute("bypassonlocal", "true"); + Trace.Verbose("Create proxy section in appconfg."); + var proxy = psHostAppConfig.CreateElement("proxy"); + proxy.SetAttribute("proxyaddress", agentProxy.ProxyAddress); + proxy.SetAttribute("bypassonlocal", "true"); - if (agentProxy.ProxyBypassList != null && agentProxy.ProxyBypassList.Count > 0) + if (agentProxy.ProxyBypassList != null && agentProxy.ProxyBypassList.Count > 0) + { + Trace.Verbose("Create bypasslist section in appconfg."); + var bypass = psHostAppConfig.CreateElement("bypasslist"); + foreach (string proxyBypass in agentProxy.ProxyBypassList) { - Trace.Verbose("Create bypasslist section in appconfg."); - var bypass = psHostAppConfig.CreateElement("bypasslist"); - foreach (string proxyBypass in agentProxy.ProxyBypassList) - { - Trace.Verbose($"Create bypasslist.add section for {proxyBypass} in appconfg."); - var add = psHostAppConfig.CreateElement("add"); - add.SetAttribute("address", proxyBypass); - bypass.AppendChild(add); - } - - defaultProxy.AppendChild(bypass); + Trace.Verbose($"Create bypasslist.add section for {proxyBypass} in appconfg."); + var add = psHostAppConfig.CreateElement("add"); + add.SetAttribute("address", proxyBypass); + bypass.AppendChild(add); } - defaultProxy.AppendChild(proxy); - system_net.AppendChild(defaultProxy); - configuration.AppendChild(system_net); + defaultProxy.AppendChild(bypass); + } - using (var appConfigStream = new FileStream(appConfig, FileMode.Open, FileAccess.ReadWrite)) - { - psHostAppConfig.Save(appConfigStream); - } + defaultProxy.AppendChild(proxy); + system_net.AppendChild(defaultProxy); + configuration.AppendChild(system_net); - ExecutionContext.Debug("Add Proxy setting in LegacyVSTSPowerShellHost.exe.config file."); - } - else + using (var appConfigStream = new FileStream(appConfig, FileMode.Open, FileAccess.ReadWrite)) { - //proxy setting exist. - ExecutionContext.Debug("Proxy setting already exist in LegacyVSTSPowerShellHost.exe.config file."); + psHostAppConfig.Save(appConfigStream); } + + ExecutionContext.Debug("Add Proxy setting in LegacyVSTSPowerShellHost.exe.config file."); + } + else + { + //proxy setting exist. + ExecutionContext.Debug("Proxy setting already exist in LegacyVSTSPowerShellHost.exe.config file."); } } diff --git a/src/Microsoft.VisualStudio.Services.Agent/Constants.cs b/src/Microsoft.VisualStudio.Services.Agent/Constants.cs index d3bed4ac19..74a2bcb158 100644 --- a/src/Microsoft.VisualStudio.Services.Agent/Constants.cs +++ b/src/Microsoft.VisualStudio.Services.Agent/Constants.cs @@ -44,7 +44,7 @@ public enum OSPlatform public static class Agent { - public static readonly string Version = "2.122.0"; + public static readonly string Version = "2.122.1"; #if OS_LINUX public static readonly OSPlatform Platform = OSPlatform.Linux;