Skip to content

Commit

Permalink
Merge branch 'releases/3.220.2' of https://github.com/microsoft/azure…
Browse files Browse the repository at this point in the history
…-pipelines-agent into releases/3.220.2
  • Loading branch information
kirill-ivlev committed May 16, 2023
2 parents 016a87c + 9620bb8 commit d68a74b
Show file tree
Hide file tree
Showing 12 changed files with 403 additions and 263 deletions.
4 changes: 4 additions & 0 deletions src/Agent.Sdk/AgentWebProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ namespace Agent.Sdk
{
public class AgentWebProxySettings
{
public static string AgentProxyUrlKey = "Agent.ProxyUrl".ToLower();
public static string AgentProxyUsernameKey = "Agent.ProxyUsername".ToLower();
public static string AgentProxyPasswordKey = "Agent.ProxyPassword".ToLower();
public static string AgentProxyBypassListKey = "Agent.ProxyBypassList".ToLower();
public string ProxyAddress { get; set; }
public string ProxyUsername { get; set; }
public string ProxyPassword { get; set; }
Expand Down
8 changes: 4 additions & 4 deletions src/Agent.Sdk/CommandPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,12 @@ private AgentCertificateSettings GetCertConfiguration()

private AgentWebProxySettings GetProxyConfiguration()
{
string proxyUrl = this.Variables.GetValueOrDefault("Agent.ProxyUrl")?.Value;
string proxyUrl = this.Variables.GetValueOrDefault(AgentWebProxySettings.AgentProxyUrlKey)?.Value;
if (!string.IsNullOrEmpty(proxyUrl))
{
string proxyUsername = this.Variables.GetValueOrDefault("Agent.ProxyUsername")?.Value;
string proxyPassword = this.Variables.GetValueOrDefault("Agent.ProxyPassword")?.Value;
List<string> proxyBypassHosts = StringUtil.ConvertFromJson<List<string>>(this.Variables.GetValueOrDefault("Agent.ProxyBypassList")?.Value ?? "[]");
string proxyUsername = this.Variables.GetValueOrDefault(AgentWebProxySettings.AgentProxyUsernameKey)?.Value;
string proxyPassword = this.Variables.GetValueOrDefault(AgentWebProxySettings.AgentProxyPasswordKey)?.Value;
List<string> proxyBypassHosts = StringUtil.ConvertFromJson<List<string>>(this.Variables.GetValueOrDefault(AgentWebProxySettings.AgentProxyBypassListKey)?.Value ?? "[]");
return new AgentWebProxySettings()
{
ProxyAddress = proxyUrl,
Expand Down
22 changes: 14 additions & 8 deletions src/Agent.Sdk/LogPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public class AgentLogPluginHostContext
public List<Pipelines.RepositoryResource> Repositories { get; set; }
public Dictionary<string, VariableValue> Variables { get; set; }
public Dictionary<string, Pipelines.TaskStepDefinitionReference> Steps { get; set; }
public AgentWebProxySettings WebProxySettings { get; private set; }

[JsonIgnore]
public VssConnection VssConnection
Expand Down Expand Up @@ -187,12 +188,12 @@ private VssConnection InitializeVssConnection()
}
}

var proxySetting = GetProxyConfiguration();
if (proxySetting != null)
WebProxySettings = GetProxyConfiguration();
if (WebProxySettings != null)
{
if (!string.IsNullOrEmpty(proxySetting.ProxyAddress))
if (!string.IsNullOrEmpty(WebProxySettings.ProxyAddress))
{
VssHttpMessageHandler.DefaultWebProxy = new AgentWebProxy(proxySetting.ProxyAddress, proxySetting.ProxyUsername, proxySetting.ProxyPassword, proxySetting.ProxyBypassList);
VssHttpMessageHandler.DefaultWebProxy = new AgentWebProxy(WebProxySettings.ProxyAddress, WebProxySettings.ProxyUsername, WebProxySettings.ProxyPassword, WebProxySettings.ProxyBypassList);
}
}

Expand Down Expand Up @@ -241,12 +242,12 @@ private AgentCertificateSettings GetCertConfiguration()

private AgentWebProxySettings GetProxyConfiguration()
{
string proxyUrl = this.Variables.GetValueOrDefault("Agent.ProxyUrl")?.Value;
string proxyUrl = this.Variables.GetValueOrDefault(AgentWebProxySettings.AgentProxyUrlKey)?.Value;
if (!string.IsNullOrEmpty(proxyUrl))
{
string proxyUsername = this.Variables.GetValueOrDefault("Agent.ProxyUsername")?.Value;
string proxyPassword = this.Variables.GetValueOrDefault("Agent.ProxyPassword")?.Value;
List<string> proxyBypassHosts = StringUtil.ConvertFromJson<List<string>>(this.Variables.GetValueOrDefault("Agent.ProxyBypassList")?.Value ?? "[]");
string proxyUsername = this.Variables.GetValueOrDefault(AgentWebProxySettings.AgentProxyUsernameKey)?.Value;
string proxyPassword = this.Variables.GetValueOrDefault(AgentWebProxySettings.AgentProxyPasswordKey)?.Value;
List<string> proxyBypassHosts = StringUtil.ConvertFromJson<List<string>>(this.Variables.GetValueOrDefault(AgentWebProxySettings.AgentProxyBypassListKey)?.Value ?? "[]");
return new AgentWebProxySettings()
{
ProxyAddress = proxyUrl,
Expand Down Expand Up @@ -275,6 +276,11 @@ public class AgentLogPluginHost
private int _shortCircuitThreshold;
private int _shortCircuitMonitorFrequency;

public Dictionary<string, IAgentLogPluginContext> PluginContexts
{
get => _pluginContexts;
}

public AgentLogPluginHost(
AgentLogPluginHostContext hostContext,
List<IAgentLogPlugin> plugins,
Expand Down
17 changes: 9 additions & 8 deletions src/Agent.Sdk/TaskPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public AgentTaskPluginExecutionContext(ITraceWriter trace)
public Dictionary<string, string> Inputs { get; set; }
public ContainerInfo Container { get; set; }
public Dictionary<string, string> JobSettings { get; set; }
public AgentWebProxySettings WebProxySettings { get; private set; }

[JsonIgnore]
public VssConnection VssConnection
Expand Down Expand Up @@ -111,12 +112,12 @@ public VssConnection InitializeVssConnection()
}
}

var proxySetting = GetProxyConfiguration();
if (proxySetting != null)
WebProxySettings = GetProxyConfiguration();
if (WebProxySettings != null)
{
if (!string.IsNullOrEmpty(proxySetting.ProxyAddress))
if (!string.IsNullOrEmpty(WebProxySettings.ProxyAddress))
{
VssHttpMessageHandler.DefaultWebProxy = new AgentWebProxy(proxySetting.ProxyAddress, proxySetting.ProxyUsername, proxySetting.ProxyPassword, proxySetting.ProxyBypassList);
VssHttpMessageHandler.DefaultWebProxy = new AgentWebProxy(WebProxySettings.ProxyAddress, WebProxySettings.ProxyUsername, WebProxySettings.ProxyPassword, WebProxySettings.ProxyBypassList);
}
}

Expand Down Expand Up @@ -319,12 +320,12 @@ public AgentCertificateSettings GetCertConfiguration()

public AgentWebProxySettings GetProxyConfiguration()
{
string proxyUrl = this.Variables.GetValueOrDefault("Agent.ProxyUrl")?.Value;
string proxyUrl = this.Variables.GetValueOrDefault(AgentWebProxySettings.AgentProxyUrlKey)?.Value;
if (!string.IsNullOrEmpty(proxyUrl))
{
string proxyUsername = this.Variables.GetValueOrDefault("Agent.ProxyUsername")?.Value;
string proxyPassword = this.Variables.GetValueOrDefault("Agent.ProxyPassword")?.Value;
List<string> proxyBypassHosts = StringUtil.ConvertFromJson<List<string>>(this.Variables.GetValueOrDefault("Agent.ProxyBypassList")?.Value ?? "[]");
string proxyUsername = this.Variables.GetValueOrDefault(AgentWebProxySettings.AgentProxyUsernameKey)?.Value;
string proxyPassword = this.Variables.GetValueOrDefault(AgentWebProxySettings.AgentProxyPasswordKey)?.Value;
List<string> proxyBypassHosts = StringUtil.ConvertFromJson<List<string>>(this.Variables.GetValueOrDefault(AgentWebProxySettings.AgentProxyBypassListKey)?.Value ?? "[]");
return new AgentWebProxySettings()
{
ProxyAddress = proxyUrl,
Expand Down
1 change: 1 addition & 0 deletions src/Agent.Sdk/Util/AzureInstanceMetadataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class AzureInstanceMetadataProvider : IDisposable
public AzureInstanceMetadataProvider()
{
_client = new HttpClient();
_client.Timeout = TimeSpan.FromSeconds(5);
}

public void Dispose()
Expand Down
20 changes: 9 additions & 11 deletions src/Agent.Worker/JobRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,15 @@ public async Task<TaskResult> RunAsync(Pipelines.AgentJobRequestMessage message,
jobContext.SetVariable(Constants.Variables.Agent.WorkFolder, HostContext.GetDirectory(WellKnownDirectory.Work), isFilePath: true);
jobContext.SetVariable(Constants.Variables.System.WorkFolder, HostContext.GetDirectory(WellKnownDirectory.Work), isFilePath: true);

try
{
jobContext.SetVariable(Constants.Variables.System.IsAzureVM, PlatformUtil.DetectAzureVM() ? "1" : "0");
jobContext.SetVariable(Constants.Variables.System.IsDockerContainer, PlatformUtil.DetectDockerContainer() ? "1" : "0");
}
catch (Exception ex)
{
// Error with telemetry shouldn't affect job run
Trace.Info($"Couldn't retrieve telemetry information");
Trace.Info(ex);
}
var azureVmCheckCommand = jobContext.GetHostContext().GetService<IAsyncCommandContext>();
azureVmCheckCommand.InitializeCommandContext(jobContext,"GetAzureVMMetada");
azureVmCheckCommand.Task = Task.Run(() => jobContext.SetVariable(Constants.Variables.System.IsAzureVM, PlatformUtil.DetectAzureVM() ? "1" : "0"));
jobContext.AsyncCommands.Add(azureVmCheckCommand);

var dockerDetectCommand = jobContext.GetHostContext().GetService<IAsyncCommandContext>();
dockerDetectCommand.InitializeCommandContext(jobContext,"DetectDockerContainer");
dockerDetectCommand.Task = Task.Run(() => jobContext.SetVariable(Constants.Variables.System.IsDockerContainer, PlatformUtil.DetectDockerContainer() ? "1" : "0"));
jobContext.AsyncCommands.Add(dockerDetectCommand);

string toolsDirectory = HostContext.GetDirectory(WellKnownDirectory.Tools);
Directory.CreateDirectory(toolsDirectory);
Expand Down
25 changes: 21 additions & 4 deletions src/Agent.Worker/StepsRunner.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using Agent.Sdk;
using Microsoft.TeamFoundation.DistributedTask.WebApi;
using Microsoft.VisualStudio.Services.Agent.Util;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

using Agent.Sdk;

using Microsoft.TeamFoundation.DistributedTask.Expressions;
using Microsoft.TeamFoundation.DistributedTask.WebApi;
using Microsoft.VisualStudio.Services.Agent.Util;

using Pipelines = Microsoft.TeamFoundation.DistributedTask.Pipelines;
using Agent.Sdk.Knob;

namespace Microsoft.VisualStudio.Services.Agent.Worker
{
Expand Down Expand Up @@ -50,6 +52,21 @@ public async Task RunAsync(IExecutionContext jobContext, IList<IStep> steps)
CancellationTokenRegistration? jobCancelRegister = null;
int stepIndex = 0;
jobContext.Variables.Agent_JobStatus = jobContext.Result ?? TaskResult.Succeeded;
// Wait till all async commands finish.
foreach (var command in jobContext.AsyncCommands ?? new List<IAsyncCommandContext>())
{
try
{
// wait async command to finish.
await command.WaitAsync();
}

catch (Exception ex)
{
// Log the error
Trace.Info($"Caught exception from async command {command.Name}: {ex}");
}
}
foreach (IStep step in steps)
{
Trace.Info($"Processing step: DisplayName='{step.DisplayName}', ContinueOnError={step.ContinueOnError}, Enabled={step.Enabled}");
Expand Down
Loading

0 comments on commit d68a74b

Please sign in to comment.