Skip to content

Commit

Permalink
Add knob to enable fetching net6.json file from GitHub (#4200)
Browse files Browse the repository at this point in the history
* Added knob "AGENT_ENABLE_FETCHING_NET6_LIST"

* implemented knob EnableFetchingNet6List in function GetNet6SupportedSystems

* Removed RuntimeKnobSource for EnableFetchingNet6List

* removed logic which fails pipeline if there is some error occurred during checking if system supports .NET 6

* fixed typo
  • Loading branch information
sergey-koryshev committed Mar 13, 2023
1 parent 3936c12 commit ad2467b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/Agent.Sdk/Knob/AgentKnobs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}
9 changes: 8 additions & 1 deletion src/Agent.Sdk/Util/PlatformUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,10 @@ private async static Task<OperatingSystem[]> 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)
Expand All @@ -335,6 +337,11 @@ private async static Task<OperatingSystem[]> GetNet6SupportedSystems()
return net6SupportedSystems;
}

if (!supportOSfileExists)
{
throw new FileNotFoundException("File with list of systems supporting .NET 6 is absent", supportOSfilePath);
}

supportOSfileContent = await File.ReadAllTextAsync(supportOSfilePath);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Agent.Worker/JobRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ public async Task<TaskResult> 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);

}
}
Expand Down

0 comments on commit ad2467b

Please sign in to comment.