Skip to content

Commit

Permalink
moved logic of checking if system supports .NET 6 to JobExtension (#4207
Browse files Browse the repository at this point in the history
)
  • Loading branch information
sergey-koryshev committed Mar 27, 2023
1 parent 7f7c16b commit e5c6c57
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 46 deletions.
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

0 comments on commit e5c6c57

Please sign in to comment.