Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make warnings/errors during checking if system supports .NET 6 being pushed to Kusto telemetry #4207

Merged
merged 3 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions src/Agent.Worker/JobExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,52 @@ public async Task<List<IStep>> InitializeJob(IExecutionContext jobContext, Pipel
context.Start();
context.Section(StringUtil.Loc("StepStarting", StringUtil.Loc("InitializeJob")));

// Check if a system supports .NET 6
PackageVersion agentVersion = new PackageVersion(BuildConstants.AgentPackage.Version);
if (agentVersion.Major < 3)
{
try
{
Trace.Verbose("Checking if your system supports .NET 6");

string systemId = PlatformUtil.GetSystemId();
SystemVersion systemVersion = PlatformUtil.GetSystemVersion();
string notSupportNet6Message = null;

if (await PlatformUtil.DoesSystemPersistsInNet6Whitelist())
{
// Check version of the system
if (!await PlatformUtil.IsNet6Supported())
{
notSupportNet6Message = $"The operating system the agent is running on is \"{systemId}\" ({systemVersion}), which will not be supported by the .NET 6 based v3 agent. Please upgrade the operating system of this host to ensure compatibility with the v3 agent. See https://aka.ms/azdo-pipeline-agent-version";
if (AgentKnobs.AgentFailOnIncompatibleOS.GetValue(jobContext).AsBoolean() &&
!AgentKnobs.AcknowledgeNoUpdates.GetValue(jobContext).AsBoolean())
{
throw new UnsupportedOsException(StringUtil.Loc("FailAgentOnUnsupportedOs"));
}
}
}
else
{
notSupportNet6Message = $"The operating system the agent is running on is \"{systemId}\" ({systemVersion}), which has not been tested with the .NET 6 based v3 agent. The v2 agent wil not automatically upgrade to the v3 agent. You can manually download the .NET 6 based v3 agent from https://github.com/microsoft/azure-pipelines-agent/releases. See https://aka.ms/azdo-pipeline-agent-version";
}

if (!string.IsNullOrWhiteSpace(notSupportNet6Message))
{
context.Warning(notSupportNet6Message);
}
}
catch (UnsupportedOsException)
{
throw;
}
catch (Exception ex)
{
Trace.Error($"Error has occurred while checking if system supports .NET 6: {ex}");
context.Warning(ex.Message);
}
}

// Set agent version variable.
context.SetVariable(Constants.Variables.Agent.Version, BuildConstants.AgentPackage.Version);
context.Output(StringUtil.Loc("AgentNameLog", context.Variables.Get(Constants.Variables.Agent.Name)));
Expand Down Expand Up @@ -592,4 +638,8 @@ private void OutputSetupInfo(IExecutionContext context)
}
}
}

public class UnsupportedOsException : Exception {
public UnsupportedOsException(string message) : base(message) { }
}
}
46 changes: 0 additions & 46 deletions src/Agent.Worker/JobRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,52 +102,6 @@ public async Task<TaskResult> RunAsync(Pipelines.AgentJobRequestMessage message,
jobContext = HostContext.CreateService<IExecutionContext>();
jobContext.InitializeJob(message, jobRequestCancellationToken);

// Check if a system supports .NET 6
PackageVersion agentVersion = new PackageVersion(BuildConstants.AgentPackage.Version);
if (agentVersion.Major < 3)
{
try
{
Trace.Verbose("Checking if your system supports .NET 6");

string systemId = PlatformUtil.GetSystemId();
SystemVersion systemVersion = PlatformUtil.GetSystemVersion();
string notSupportNet6Message = null;

if (await PlatformUtil.DoesSystemPersistsInNet6Whitelist())
{
// Check version of the system
if (!await PlatformUtil.IsNet6Supported())
{
notSupportNet6Message = $"The operating system the agent is running on is \"{systemId}\" ({systemVersion}), which will not be supported by the .NET 6 based v3 agent. Please upgrade the operating system of this host to ensure compatibility with the v3 agent. See https://aka.ms/azdo-pipeline-agent-version";
if (AgentKnobs.AgentFailOnIncompatibleOS.GetValue(jobContext).AsBoolean() &&
!AgentKnobs.AcknowledgeNoUpdates.GetValue(jobContext).AsBoolean())
{
jobContext.Error(StringUtil.Loc("FailAgentOnUnsupportedOs"));
return await CompleteJobAsync(jobServer, jobContext, message, TaskResult.Failed);
}
}
}
else
{
notSupportNet6Message = $"The operating system the agent is running on is \"{systemId}\" ({systemVersion}), which has not been tested with the .NET 6 based v3 agent. The v2 agent wil not automatically upgrade to the v3 agent. You can manually download the .NET 6 based v3 agent from https://github.com/microsoft/azure-pipelines-agent/releases. See https://aka.ms/azdo-pipeline-agent-version";
}

if (!string.IsNullOrWhiteSpace(notSupportNet6Message))
{


jobContext.AddIssue(new Issue() { Type = IssueType.Warning, Message = notSupportNet6Message });
}
}
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}");

}
}

Trace.Info("Starting the job execution context.");
jobContext.Start();
jobContext.Section(StringUtil.Loc("StepStarting", message.JobDisplayName));
Expand Down