private async Task <bool> UpdateNeeded(string targetVersion, CancellationToken token) { // when talk to old version tfs server, always prefer latest package. // old server won't send target version as part of update message. if (string.IsNullOrEmpty(targetVersion)) { var packages = await _agentServer.GetPackagesAsync(_packageType, _platform, 1, token); if (packages == null || packages.Count == 0) { Trace.Info($"There is no package for {_packageType} and {_platform}."); return(false); } _targetPackage = packages.FirstOrDefault(); } else { _targetPackage = await _agentServer.GetPackageAsync(_packageType, _platform, targetVersion, token); if (_targetPackage == null) { Trace.Info($"There is no package for {_packageType} and {_platform} with version {targetVersion}."); return(false); } } Trace.Info($"Version '{_targetPackage.Version}' of '{_targetPackage.Type}' package available in server."); PackageVersion serverVersion = new PackageVersion(_targetPackage.Version); Trace.Info($"Current running agent version is {BuildConstants.AgentPackage.Version}"); PackageVersion agentVersion = new PackageVersion(BuildConstants.AgentPackage.Version); return(serverVersion.CompareTo(agentVersion) > 0); }
private async Task <bool> UpdateNeeded(string targetVersion, CancellationToken token) { // when talk to old version tfs server, always prefer latest package. // old server won't send target version as part of update message. if (string.IsNullOrEmpty(targetVersion)) { var packages = await _agentServer.GetPackagesAsync(_packageType, _platform, 1, token); if (packages == null || packages.Count == 0) { Trace.Info($"There is no package for {_packageType} and {_platform}."); return(false); } _targetPackage = packages.FirstOrDefault(); } else { _targetPackage = await _agentServer.GetPackageAsync(_packageType, _platform, targetVersion, token); if (_targetPackage == null) { Trace.Info($"There is no package for {_packageType} and {_platform} with version {targetVersion}."); return(false); } } Trace.Info($"Version '{_targetPackage.Version}' of '{_targetPackage.Type}' package available in server."); PackageVersion serverVersion = new PackageVersion(_targetPackage.Version); Trace.Info($"Current running agent version is {BuildConstants.AgentPackage.Version}"); PackageVersion agentVersion = new PackageVersion(BuildConstants.AgentPackage.Version); if (serverVersion.CompareTo(agentVersion) > 0) { return(true); } if (AgentKnobs.DisableAgentDowngrade.GetValue(_knobContext).AsBoolean()) { Trace.Info("Agent downgrade disabled, skipping update"); return(false); } // Always return true for newer agent versions unless they're exactly equal to enable auto rollback (this feature was introduced after 2.165.0) if (serverVersion.CompareTo(agentVersion) != 0) { _terminal.WriteLine(StringUtil.Loc("AgentDowngrade")); return(true); } return(false); }