diff --git a/src/Agent.Sdk/Knob/AgentKnobs.cs b/src/Agent.Sdk/Knob/AgentKnobs.cs index 3bed4e2e3d..f85e25ae8f 100644 --- a/src/Agent.Sdk/Knob/AgentKnobs.cs +++ b/src/Agent.Sdk/Knob/AgentKnobs.cs @@ -431,5 +431,11 @@ public class AgentKnobs new RuntimeKnobSource("AGENT_DISABLE_DRAIN_QUEUES_AFTER_TASK"), new EnvironmentKnobSource("AGENT_DISABLE_DRAIN_QUEUES_AFTER_TASK"), new BuiltInDefaultKnobSource("false")); + + public static readonly Knob EnableFetchingNet6List = new Knob( + nameof(EnableFetchingNet6List), + "Forces the agent to fetch list of .NET 6 supporting systems from server", + new EnvironmentKnobSource("AGENT_ENABLE_FETCHING_NET6_LIST"), + new BuiltInDefaultKnobSource("false")); } } diff --git a/src/Agent.Sdk/Util/PlatformUtil.cs b/src/Agent.Sdk/Util/PlatformUtil.cs index 14499f9a4d..37590a1f89 100644 --- a/src/Agent.Sdk/Util/PlatformUtil.cs +++ b/src/Agent.Sdk/Util/PlatformUtil.cs @@ -317,8 +317,10 @@ private async static Task GetNet6SupportedSystems() string serverFileUrl = "https://raw.githubusercontent.com/microsoft/azure-pipelines-agent/master/src/Agent.Listener/net6.json"; string supportOSfilePath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "net6.json"); string supportOSfileContent; + bool supportOSfileExists = File.Exists(supportOSfilePath); - if (!File.Exists(supportOSfilePath) || File.GetLastWriteTimeUtc(supportOSfilePath) < DateTime.UtcNow.AddHours(-1)) + if ((!supportOSfileExists || File.GetLastWriteTimeUtc(supportOSfilePath) < DateTime.UtcNow.AddHours(-1)) + && AgentKnobs.EnableFetchingNet6List.GetValue(_knobContext).AsBoolean()) { HttpResponseMessage response = await httpClient.GetAsync(serverFileUrl); if (!response.IsSuccessStatusCode) @@ -335,6 +337,11 @@ private async static Task GetNet6SupportedSystems() return net6SupportedSystems; } + if (!supportOSfileExists) + { + throw new FileNotFoundException("File with list of systems supporting .NET 6 is absent", supportOSfilePath); + } + supportOSfileContent = await File.ReadAllTextAsync(supportOSfilePath); } diff --git a/src/Agent.Worker/JobRunner.cs b/src/Agent.Worker/JobRunner.cs index dfbe40ab0f..12b8df185f 100644 --- a/src/Agent.Worker/JobRunner.cs +++ b/src/Agent.Worker/JobRunner.cs @@ -142,8 +142,8 @@ public async Task RunAsync(Pipelines.AgentJobRequestMessage message, } catch (Exception ex) { + jobContext.Warning($"Error has occurred while checking if system supports .NET 6: {ex.Message}"); Trace.Error($"Error has occurred while checking if system supports .NET 6: {ex}"); - return await CompleteJobAsync(jobServer, jobContext, message, TaskResult.Failed); } }