Skip to content

Commit

Permalink
moved logic around checking system version to JobRunner
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-koryshev committed Jan 27, 2023
1 parent d003c99 commit 77a439d
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 60 deletions.
60 changes: 0 additions & 60 deletions src/Agent.Worker/ExecutionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -666,66 +666,6 @@ public void InitializeJob(Pipelines.AgentJobRequestMessage message, Cancellation

// Hook up JobServerQueueThrottling event, we will log warning on server tarpit.
_jobServerQueue.JobServerQueueThrottling += JobServerQueueThrottling_EventReceived;

// Get version of system where agent is running
string systemId = null;
SystemVersion systemVersion = null;

try
{
systemId = PlatformUtil.GetSystemId();
systemVersion = PlatformUtil.GetSystemVersion();
}
catch (Exception ex)
{
Trace.Error($"Error has occurred while checking if system supports .NET 6: {ex}");
}

// Check if system is RHEL 6 and throw exception then
bool acknowledgeNoUpdatesKnob = AgentKnobs.AcknowledgeNoUpdates.GetValue(this).AsBoolean();
if (!acknowledgeNoUpdatesKnob && systemId == "rhel" && systemVersion.Equals(new SystemVersion("6")))
{
string errorMessage = "Red Hat 6 will no longer receive updates of the Pipelines Agent. To be able to continue run pipelines please upgrade the operating system or set an environment variable or agent kbob \"AGENT_ACKNOWLEDGE_NO_UPDATES\" to \"true\". See https://aka.ms/azdo-pipeline-agent-rhel6 for more information.";
Trace.Error(errorMessage);
AddIssue(new Issue() { Type = IssueType.Error, Message = errorMessage });
throw new Exception(errorMessage);
}

// Check if a system supports .NET 6
PackageVersion agentVersion = new PackageVersion(BuildConstants.AgentPackage.Version);

if (agentVersion.Major < 3 && systemId != null && systemVersion != null)
{
try
{
Trace.Verbose("Checking if your system supports .NET 6");


string notSupportNet6Message = null;

if (PlatformUtil.DoesSystemPersistsInNet6Whitelist())
{
// Check version of the system
if (!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";
}
}
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))
{
AddIssue(new Issue() { Type = IssueType.Warning, Message = notSupportNet6Message });
}
}
catch (Exception ex)
{
Trace.Error($"Error has occurred while checking if system supports .NET 6: {ex}");
}
}
}

private string GetWorkspaceIdentifier(Pipelines.AgentJobRequestMessage message)
Expand Down
61 changes: 61 additions & 0 deletions src/Agent.Worker/JobRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,67 @@ public async Task<TaskResult> RunAsync(Pipelines.AgentJobRequestMessage message,
// Create the job execution context.
jobContext = HostContext.CreateService<IExecutionContext>();
jobContext.InitializeJob(message, jobRequestCancellationToken);

// Get version of system where agent is running
string systemId = null;
SystemVersion systemVersion = null;

try
{
systemId = PlatformUtil.GetSystemId();
systemVersion = PlatformUtil.GetSystemVersion();
}
catch (Exception ex)
{
Trace.Error($"Error has occurred while checking if system supports .NET 6: {ex}");
}

// Check if system is RHEL 6 and throw exception then
bool acknowledgeNoUpdatesKnob = AgentKnobs.AcknowledgeNoUpdates.GetValue(jobContext).AsBoolean();
if (!acknowledgeNoUpdatesKnob && systemId == "rhel" && systemVersion.Equals(new SystemVersion("6")))
{
string errorMessage = "Red Hat 6 will no longer receive updates of the Pipelines Agent. To be able to continue run pipelines please upgrade the operating system or set an environment variable or agent kbob \"AGENT_ACKNOWLEDGE_NO_UPDATES\" to \"true\". See https://aka.ms/azdo-pipeline-agent-rhel6 for more information.";
Trace.Error(errorMessage);
jobContext.Error(errorMessage);
return await CompleteJobAsync(jobServer, jobContext, message, TaskResult.Failed);
}

// Check if a system supports .NET 6
PackageVersion agentVersion = new PackageVersion(BuildConstants.AgentPackage.Version);

if (agentVersion.Major < 3 && systemId != null && systemVersion != null)
{
try
{
Trace.Verbose("Checking if your system supports .NET 6");


string notSupportNet6Message = null;

if (PlatformUtil.DoesSystemPersistsInNet6Whitelist())
{
// Check version of the system
if (!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";
}
}
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)
{
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 77a439d

Please sign in to comment.