Skip to content

Commit

Permalink
Extract image version output to a method
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandrlevochkin committed Jul 12, 2024
1 parent e74c3d9 commit 19cab8f
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/Agent.Worker/JobExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,7 @@ public async Task<List<IStep>> InitializeJob(IExecutionContext jobContext, Pipel

// Machine specific setup info
OutputSetupInfo(context);

string imageVersion = System.Environment.GetEnvironmentVariable(Constants.ImageVersionVariable);
if (imageVersion != null)
{
context.Output(StringUtil.Loc("ImageVersionLog", imageVersion));
var telemetryData = new Dictionary<string, string>()
{
{ "JobId", context?.Variables?.System_JobId?.ToString() ?? string.Empty },
{ "ImageVersion", imageVersion },
};
PublishTelemetry(context, telemetryData, "ImageVersionTelemetry");
}
OutputImageVersion(context);
context.Output(StringUtil.Loc("UserNameLog", System.Environment.UserName));

// Print proxy setting information for better diagnostic experience
Expand Down Expand Up @@ -261,6 +250,7 @@ public async Task<List<IStep>> InitializeJob(IExecutionContext jobContext, Pipel
Trace.Info($"Caught exception from async command WindowsPreinstalledGitTelemetry: {ex}");
}
}

if (PlatformUtil.RunningOnWindows)
{
// This is for internal testing and is not publicly supported. This will be removed from the agent at a later time.
Expand Down Expand Up @@ -544,7 +534,9 @@ public async Task<List<IStep>> InitializeJob(IExecutionContext jobContext, Pipel
{ "JobResult", TaskResult.Failed.ToString() },
{ "TracePoint", "110" },
};

PublishTelemetry(jobContext, telemetryData, "AgentShutdown");

Trace.Error($"Caught Agent Shutdown exception from JobExtension Initialization: {ex.Message}");
context.Error(ex);
context.Result = TaskResult.Failed;
Expand Down Expand Up @@ -701,6 +693,23 @@ private Dictionary<int, Process> SnapshotProcesses()
return snapshot;
}

private void OutputImageVersion(IExecutionContext context)
{
string imageVersion = System.Environment.GetEnvironmentVariable(Constants.ImageVersionVariable);

if (imageVersion != null)
{
context.Output(StringUtil.Loc("ImageVersionLog", imageVersion));
var telemetryData = new Dictionary<string, string>()
{
{ "JobId", context?.Variables?.System_JobId?.ToString() ?? string.Empty },
{ "ImageVersion", imageVersion },
};

PublishTelemetry(context, telemetryData, "ImageVersionTelemetry");
}
}

private void OutputSetupInfo(IExecutionContext context)
{
try
Expand Down

0 comments on commit 19cab8f

Please sign in to comment.