diff --git a/src/Runner.Sdk/RunnerWebProxy.cs b/src/Runner.Sdk/RunnerWebProxy.cs index 71d9d1e6c..18ba50120 100644 --- a/src/Runner.Sdk/RunnerWebProxy.cs +++ b/src/Runner.Sdk/RunnerWebProxy.cs @@ -21,6 +21,7 @@ namespace GitHub.Runner.Sdk private string _httpsProxyAddress; private string _httpsProxyUsername; private string _httpsProxyPassword; + private string _noProxyString; private readonly List _noProxyList = new List(); private readonly HashSet _noProxyUnique = new HashSet(StringComparer.OrdinalIgnoreCase); @@ -33,6 +34,7 @@ namespace GitHub.Runner.Sdk public string HttpsProxyAddress => _httpsProxyAddress; public string HttpsProxyUsername => _httpsProxyUsername; public string HttpsProxyPassword => _httpsProxyPassword; + public string NoProxyString => _noProxyString; public List NoProxyList => _noProxyList; @@ -121,6 +123,7 @@ namespace GitHub.Runner.Sdk if (!string.IsNullOrEmpty(noProxyList)) { + _noProxyString = noProxyList; var noProxyListSplit = noProxyList.Split(',', StringSplitOptions.RemoveEmptyEntries); foreach (string noProxy in noProxyListSplit) { diff --git a/src/Runner.Worker/Container/ContainerInfo.cs b/src/Runner.Worker/Container/ContainerInfo.cs index 8d3292496..a1cc2782c 100644 --- a/src/Runner.Worker/Container/ContainerInfo.cs +++ b/src/Runner.Worker/Container/ContainerInfo.cs @@ -63,6 +63,8 @@ namespace GitHub.Runner.Worker.Container UserMountVolumes[volume] = volume; } } + + UpdateWebProxyEnv(hostContext.WebProxy); } public string ContainerId { get; set; } @@ -222,6 +224,26 @@ namespace GitHub.Runner.Worker.Container { _pathMappings.Insert(0, new PathMapping(hostCommonPath, containerCommonPath)); } + + private void UpdateWebProxyEnv(RunnerWebProxy webProxy) + { + // Set common forms of proxy variables if configured in Runner and not set directly by container.env + if (!String.IsNullOrEmpty(webProxy.HttpProxyAddress)) + { + ContainerEnvironmentVariables.TryAdd("HTTP_PROXY", webProxy.HttpProxyAddress); + ContainerEnvironmentVariables.TryAdd("http_proxy", webProxy.HttpProxyAddress); + } + if (!String.IsNullOrEmpty(webProxy.HttpsProxyAddress)) + { + ContainerEnvironmentVariables.TryAdd("HTTPS_PROXY", webProxy.HttpsProxyAddress); + ContainerEnvironmentVariables.TryAdd("https_proxy", webProxy.HttpsProxyAddress); + } + if (!String.IsNullOrEmpty(webProxy.NoProxyString)) + { + ContainerEnvironmentVariables.TryAdd("NO_PROXY", webProxy.NoProxyString); + ContainerEnvironmentVariables.TryAdd("no_proxy", webProxy.NoProxyString); + } + } } public class MountVolume