Skip to content

Commit 2abebc7

Browse files
Merge branch 'master' into users/surajitshil-03/test
2 parents 2bc4bff + 188c851 commit 2abebc7

File tree

65 files changed

+6294
-416
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+6294
-416
lines changed

src/Agent.Listener/Configuration.Windows/AutoLogonManager.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,26 @@ private void RestartBasedOnUserInput(CommandSettings command)
208208
//ExecuteAsync API of ProcessInvoker waits for the process to exit
209209
var args = $@"-r -t 15 -c ""{msg}""";
210210
Trace.Info($"Shutdown.exe path: {shutdownExePath}. Arguments: {args}");
211-
Process.Start(shutdownExePath, $@"{args}");
211+
212+
try
213+
{
214+
Process.Start(shutdownExePath, $@"{args}");
215+
}
216+
catch (System.ComponentModel.Win32Exception w32Ex)
217+
{
218+
Trace.Error($"Failed to start shutdown process: Win32 error {w32Ex.NativeErrorCode}: {w32Ex.Message}");
219+
_terminal.WriteError($"Failed to restart machine automatically. Please restart manually. Error: {w32Ex.Message}");
220+
}
221+
catch (FileNotFoundException fnfEx)
222+
{
223+
Trace.Error($"Shutdown executable not found at '{shutdownExePath}': {fnfEx.Message}");
224+
_terminal.WriteError($"Cannot find shutdown.exe. Please restart machine manually.");
225+
}
226+
catch (Exception ex)
227+
{
228+
Trace.Error($"Unexpected error starting shutdown process: {ex.Message} {ex}");
229+
_terminal.WriteError($"Failed to restart machine automatically. Please restart manually. Error: {ex.Message}");
230+
}
212231
}
213232
else
214233
{

src/Agent.Listener/Configuration/ConfigurationManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ public async Task ConfigureAsync(CommandSettings command)
244244
while (true)
245245
{
246246
agentSettings.AgentName = command.GetAgentName();
247-
Trace.Info($"Agent registration attempt - Name: '{agentSettings.AgentName}', Pool: '{agentSettings.PoolName}' (ID: {agentSettings.PoolId}), ReplaceMode: {command.GetReplace()}");
247+
Trace.Info($"Agent registration attempt - Name: '{agentSettings.AgentName}', Pool: '{agentSettings.PoolName}' (ID: {agentSettings.PoolId})");
248248

249249
// Get the system capabilities.
250250
// TODO: Hook up to ctrl+c cancellation token.

src/Agent.Listener/Configuration/ConfigurationProvider.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,16 @@ private async Task<string> GetAzureSubscriptionIdAsync()
369369
azureSubscriptionId = string.Empty;
370370
}
371371
}
372+
catch (HttpRequestException httpEx)
373+
{
374+
azureSubscriptionId = string.Empty;
375+
Trace.Info($"HTTP error accessing Azure IMDS: {httpEx.Message}");
376+
}
377+
catch (TaskCanceledException tcEx) when (tcEx.InnerException is System.TimeoutException)
378+
{
379+
azureSubscriptionId = string.Empty;
380+
Trace.Info($"Timeout accessing Azure IMDS (not running on Azure): {tcEx.Message}");
381+
}
372382
catch (SocketException ex)
373383
{
374384
azureSubscriptionId = string.Empty;
@@ -379,6 +389,7 @@ private async Task<string> GetAzureSubscriptionIdAsync()
379389
// An exception will be thrown if the Agent Machine is a non-Azure VM.
380390
azureSubscriptionId = string.Empty;
381391
Trace.Info($"GetAzureSubscriptionId ex: {ex.Message}");
392+
Trace.Info(ex.ToString());
382393
}
383394
}
384395

src/Agent.Listener/JobDispatcher.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,7 @@ await processChannel.SendAsync(
11931193
catch (Exception ex)
11941194
{
11951195
Trace.Warning($"Failed to send flush logs request to worker: {ex.Message}");
1196+
Trace.Warning(ex.ToString());
11961197
}
11971198

11981199
// Now wait for the additional 1 minute log flushing period

src/Agent.Listener/MessageListener.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Microsoft.VisualStudio.Services.Common;
99
using System;
1010
using System.Collections.Generic;
11+
using System.Net.Http;
1112
using System.Net.Sockets;
1213
using System.Threading;
1314
using System.Threading.Tasks;

src/Agent.Listener/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ private static async Task<int> MainAsync(IHostContext context, string[] args)
6868
{
6969
terminal.WriteError(StringUtil.Loc("ErrorOccurred", e.Message));
7070
trace.Error(StringUtil.Format($"Directory permission validation failed - insufficient permissions - {0}", e.Message));
71+
trace.Error(e);
7172
return Constants.Agent.ReturnCode.TerminatedError;
7273
}
7374

src/Agent.Plugins/TFCliManager.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ public override TfsVCFeatures Features
3838

3939
public static readonly int RetriesOnFailure = 3;
4040

41-
private string TfPath => AgentKnobs.InstallLegacyTfExe.GetValue(ExecutionContext).AsBoolean()
42-
? Path.Combine(ExecutionContext.Variables.GetValueOrDefault("Agent.HomeDirectory")?.Value, "externals", "tf-legacy")
43-
: Path.Combine(ExecutionContext.Variables.GetValueOrDefault("Agent.HomeDirectory")?.Value, "externals", "tf");
41+
private string TfPath => VarUtil.GetTfDirectoryPath(ExecutionContext);
4442

4543
public string FilePath => Path.Combine(TfPath, "tf.exe");
4644

src/Agent.Plugins/TfsVCSourceProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ public async Task GetSourceAsync(
101101
if (PlatformUtil.RunningOnWindows)
102102
{
103103
// Set TFVC_BUILDAGENT_POLICYPATH
104-
string tfDirectoryName = AgentKnobs.InstallLegacyTfExe.GetValue(executionContext).AsBoolean() ? "tf-legacy" : "tf";
105-
string policyDllPath = Path.Combine(executionContext.Variables.GetValueOrDefault("Agent.HomeDirectory")?.Value, "externals", tfDirectoryName, "Microsoft.TeamFoundation.VersionControl.Controls.dll");
104+
string TfPath = VarUtil.GetTfDirectoryPath(executionContext);
105+
string policyDllPath = Path.Combine(TfPath, "Microsoft.TeamFoundation.VersionControl.Controls.dll");
106106
ArgUtil.File(policyDllPath, nameof(policyDllPath));
107107
const string policyPathEnvKey = "TFVC_BUILDAGENT_POLICYPATH";
108108
executionContext.Output(StringUtil.Loc("SetEnvVar", policyPathEnvKey));

src/Agent.Sdk/CommandPlugin.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public interface IAgentCommandPlugin
2828
Task ProcessCommandAsync(AgentCommandPluginExecutionContext executionContext, CancellationToken token);
2929
}
3030

31-
public class AgentCommandPluginExecutionContext : ITraceWriter
31+
public class AgentCommandPluginExecutionContext : ITraceWriter, IKnobValueContext
3232
{
3333
private VssConnection _connection;
3434
private readonly object _stdoutLock = new object();
@@ -69,7 +69,7 @@ public void Verbose(string message, [CallerMemberName] string operation = "")
6969
#if DEBUG
7070
Debug(message);
7171
#else
72-
string vstsAgentTrace = AgentKnobs.TraceVerbose.GetValue(UtilKnobValueContext.Instance()).AsString();
72+
string vstsAgentTrace = AgentKnobs.TraceVerbose.GetValue(this).AsString();
7373
if (!string.IsNullOrEmpty(vstsAgentTrace))
7474
{
7575
Debug(message);
@@ -212,5 +212,15 @@ private AgentWebProxySettings GetProxyConfiguration()
212212
return null;
213213
}
214214
}
215+
216+
string IKnobValueContext.GetVariableValueOrDefault(string variableName)
217+
{
218+
return Variables.GetValueOrDefault(variableName)?.Value;
219+
}
220+
221+
IScopedEnvironment IKnobValueContext.GetScopedEnvironment()
222+
{
223+
return new SystemEnvironment();
224+
}
215225
}
216226
}

src/Agent.Sdk/ContainerInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public ContainerInfo(Pipelines.ContainerResource container, Boolean isJobContain
9494
public bool IsJobContainer { get; set; }
9595
public bool MapDockerSocket { get; set; }
9696
public bool NeedsNode16Redirect { get; set; }
97+
public bool NeedsNode20Redirect { get; set; }
9798
public PlatformUtil.OS ImageOS
9899
{
99100
get

0 commit comments

Comments
 (0)