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

Update .NET 3.1 Agent to never upgrade to .NET 6 on unsupported OS #4064

Merged
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
ecb3843
implemented logic to get Id and VersionId on linux
sergey-koryshev Nov 10, 2022
9b5a197
output linux id and linux version in SelfUpdater class
sergey-koryshev Nov 10, 2022
58050f6
fixed issue with quotes
sergey-koryshev Nov 10, 2022
a995829
refactored logic to determine version of OS; implemented logic for ma…
sergey-koryshev Nov 16, 2022
65f1c27
commented unused code
sergey-koryshev Nov 16, 2022
6a2e0e7
Refactored logic around getting version of windows
sergey-koryshev Nov 16, 2022
b7f6b5c
updated list of supporeted OS by .NET 6
sergey-koryshev Nov 17, 2022
6365a55
improved logging
sergey-koryshev Nov 17, 2022
8a38ac1
removed windows 11 from list since it's detected as windows 10
sergey-koryshev Nov 18, 2022
c8301ee
improved log messages
sergey-koryshev Nov 18, 2022
cea6d7a
removed dummy condition
sergey-koryshev Nov 18, 2022
71fb4d8
corrected log message
sergey-koryshev Nov 18, 2022
d587850
Merge branch 'master' into users/sergey.koryshev/1994084-prevent-upda…
sergey-koryshev Nov 18, 2022
25e17b0
Converted properties "SystemId" and "SystemVersion" to methods
sergey-koryshev Nov 22, 2022
b91a7d0
removed unused "using"
sergey-koryshev Nov 22, 2022
1da16ba
added amazon linux to whitelist
sergey-koryshev Nov 24, 2022
40e7e80
Changed warning message
sergey-koryshev Nov 24, 2022
a88c0bd
Merge branch 'master' into users/sergey.koryshev/1994084-prevent-upda…
kirill-ivlev Nov 29, 2022
63b6c99
corrected warning message
sergey-koryshev Nov 30, 2022
5a75558
small refactoring
sergey-koryshev Nov 30, 2022
b9c501a
Merge branch 'master' into users/sergey.koryshev/1994084-prevent-upda…
sergey-koryshev Nov 30, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Agent.Listener/Agent.Listener.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@
<PackageReference Include="System.ServiceProcess.ServiceController" Version="4.4.0" />
<PackageReference Include="vss-api-netcore" Version="$(VssApiVersion)" />
</ItemGroup>

<ItemGroup>
<None Update="net6.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
67 changes: 67 additions & 0 deletions src/Agent.Listener/SelfUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.VisualStudio.Services.Agent.Util;
using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.WebApi;
using Newtonsoft.Json;
using System;
using System.Diagnostics;
using System.IO;
Expand Down Expand Up @@ -147,6 +148,36 @@ private async Task<bool> UpdateNeeded(string targetVersion, CancellationToken to
Trace.Info($"Current running agent version is {BuildConstants.AgentPackage.Version}");
PackageVersion agentVersion = new PackageVersion(BuildConstants.AgentPackage.Version);

//Checking if current system support .NET 6 agent
if (agentVersion.Major == 2 && serverVersion.Major == 3)
{
Trace.Verbose("Checking if your system supports .NET 6");

try
{
OS[] supportedSystems = GetSupportedSystemsNet6();

string systemId = PlatformUtil.GetSystemId();
OSVersion systemVersion = PlatformUtil.GetSystemVersion();

Trace.Verbose($"The system you are running on: \"{systemId}\" ({systemVersion})");

if (!supportedSystems.Any((system) => system.Equals(systemId, systemVersion)))
{
Trace.Warning($"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://devblogs.microsoft.com/devops/upgrade-of-net-agent-for-azure-pipelines/");
return false;
}
else
{
Trace.Verbose("The system persists in the list of systems supporting .NET 6");
}
}
catch (Exception ex)
{
Trace.Error($"Error has occurred while checking if system supports .NET 6: {ex} ");
sergey-koryshev marked this conversation as resolved.
Show resolved Hide resolved
}
}

if (serverVersion.CompareTo(agentVersion) > 0)
{
return true;
Expand Down Expand Up @@ -646,6 +677,18 @@ private bool VerifyAgentAuthenticode(string agentFolderPath)

return true;
}

private OS[] GetSupportedSystemsNet6()
{
string supportOSfilePath = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Bin), "net6.json");
if (!File.Exists(supportOSfilePath))
{
return Array.Empty<OS>();
}

string supportOSfileContent = File.ReadAllText(supportOSfilePath);
return JsonConvert.DeserializeObject<OS[]>(supportOSfileContent)!;
}
}

public class UpdaterKnobValueContext : IKnobValueContext
Expand All @@ -660,4 +703,28 @@ public IScopedEnvironment GetScopedEnvironment()
return new SystemEnvironment();
}
}

public class OS
{
public string Id { get; set; }

public OSVersion[] Versions { get; set; }

public OS() { }

public bool Equals(string systemId, OSVersion systemVersion)
{
if (!this.Id.Equals(systemId, StringComparison.OrdinalIgnoreCase))
{
return false;
}

if (this.Versions.Length == 0)
{
return false;
}

return this.Versions.Any(version => version.Equals(systemVersion));
}
}
}
129 changes: 129 additions & 0 deletions src/Agent.Listener/net6.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
[
{
"id": "alpine",
"versions": [
{
"name": "3.13+"
}
]
},
{
"id": "amzn",
"versions": [
{
"name": "2"
}
]
},
{
"id": "centos",
"versions": [
{
"name": "7+"
}
]
},
{
"id": "debian",
"versions": [
{
"name": "10+"
}
]
},
{
"id": "fedora",
"versions": [
{
"name": "33+"
}
]
},
{
"id": "macOS",
"versions": [
{
"name": "10.15+"
}
]
},
{
"id": "opensuse-leap",
"versions": [
{
"name": "15+"
}
]
},
{
"id": "rhel",
"versions": [
{
"name": "7+"
}
]
},
{
"id": "sles",
"versions": [
{
"name": "12.2+"
}
]
},
{
"id": "ubuntu",
"versions": [
{
"name": "16.04"
},
{
"name": "18.04"
},
{
"name": "20.04+"
}

]
},
{
"id": "Windows Client",
"versions": [
{
"name": "7",
"version": "7601+"
},
{
"name": "8.1"
},
{
"name": "10",
"version": "14393+"
}
]
},
{
"id": "Windows Nano Server",
"versions": [
{
"version": "17763+"
}
]
},
{
"id": "Windows Server",
"versions": [
{
"name": "2012+"
}
]
},
{
"id": "Windows Server Core",
"versions": [
{
"name": "2012+"
}
]
}
]