Skip to content

Commit

Permalink
Install legacy tf, vstsom, vstshost tools
Browse files Browse the repository at this point in the history
  • Loading branch information
v-levockina committed Sep 11, 2024
1 parent fc69091 commit fa94da5
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/Agent.Sdk/Knob/AgentKnobs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -761,9 +761,10 @@ public class AgentKnobs

public static readonly Knob InstallLegacyTfExe = new Knob(
nameof(InstallLegacyTfExe),
"If true, agent will install the previous version of TF.exe in the tf-legacy and vstsom-legacy directories",
"If true, the agent will install the legacy versions of TF, vstsom and vstshost",
new RuntimeKnobSource("AGENT_INSTALL_LEGACY_TF_EXE"),
new EnvironmentKnobSource("AGENT_INSTALL_LEGACY_TF_EXE"),
new PipelineFeatureSource("InstallLegacyTfExe"),
new BuiltInDefaultKnobSource("false"));
}
}
26 changes: 21 additions & 5 deletions src/Agent.Worker/Handlers/LegacyPowerShellHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ private List<Tuple<String, List<Tuple<String, String>>>> GetAdditionalCommandsFo
}

// Initialize our Azure Support (imports the module, sets up the Azure subscription)
string path = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Externals), "vstshost");
string path = AgentKnobs.InstallLegacyTfExe.GetValue(ExecutionContext).AsBoolean()
? Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Externals), "vstshost-legacy")
: Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Externals), "vstshost");

string azurePSM1 = Path.Combine(path, "Microsoft.TeamFoundation.DistributedTask.Task.Deployment.Azure\\Microsoft.TeamFoundation.DistributedTask.Task.Deployment.Azure.psm1");

Trace.Verbose("AzurePowerShellHandler.UpdatePowerShellEnvironment - AddCommand(Import-Module)");
Expand Down Expand Up @@ -211,9 +214,13 @@ public async Task RunAsync()
? HostContext.GetDirectory(WellKnownDirectory.ServerOMLegacy)
: HostContext.GetDirectory(WellKnownDirectory.ServerOM);

string targetDirectory = AgentKnobs.InstallLegacyTfExe.GetValue(ExecutionContext).AsBoolean()
? HostContext.GetDirectory(WellKnownDirectory.LegacyPSHostLegacy)
: HostContext.GetDirectory(WellKnownDirectory.LegacyPSHost);

IOUtil.CopyDirectory(
source: sourceDirectory,
target: HostContext.GetDirectory(WellKnownDirectory.LegacyPSHost),
target: targetDirectory,
cancellationToken: ExecutionContext.CancellationToken);
Trace.Info("Finished copying files.");

Expand All @@ -236,7 +243,11 @@ public async Task RunAsync()

try
{
String vstsPSHostExe = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.LegacyPSHost), "LegacyVSTSPowerShellHost.exe");
String vstsPSHostExeDirectory = AgentKnobs.InstallLegacyTfExe.GetValue(ExecutionContext).AsBoolean()
? HostContext.GetDirectory(WellKnownDirectory.LegacyPSHostLegacy)
: HostContext.GetDirectory(WellKnownDirectory.LegacyPSHost);

String vstsPSHostExe = Path.Combine(vstsPSHostExeDirectory, "LegacyVSTSPowerShellHost.exe");
Int32 exitCode = await processInvoker.ExecuteAsync(workingDirectory: workingDirectory,
fileName: vstsPSHostExe,
arguments: "",
Expand Down Expand Up @@ -438,10 +449,15 @@ protected virtual void AddLegacyHostEnvironmentVariables(string scriptFile, stri

private void AddProxySetting(IVstsAgentWebProxy agentProxy)
{
string appConfig = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.LegacyPSHost), _appConfigFileName);
string psHostDirectory = AgentKnobs.InstallLegacyTfExe.GetValue(ExecutionContext).AsBoolean()
? HostContext.GetDirectory(WellKnownDirectory.LegacyPSHostLegacy)
: HostContext.GetDirectory(WellKnownDirectory.LegacyPSHost);

string appConfig = Path.Combine(psHostDirectory, _appConfigFileName);

ArgUtil.File(appConfig, _appConfigFileName);

string appConfigRestore = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.LegacyPSHost), _appConfigRestoreFileName);
string appConfigRestore = Path.Combine(psHostDirectory, _appConfigRestoreFileName);
if (!File.Exists(appConfigRestore))
{
Trace.Info("Take snapshot of current appconfig for restore modified appconfig.");
Expand Down
15 changes: 15 additions & 0 deletions src/Agent.Worker/TfManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.VisualStudio.Services.Agent.Util;
using Microsoft.VisualStudio.Services.Agent.Worker;
using System;
using System.IO;
using System.IO.Compression;
Expand Down Expand Up @@ -56,6 +57,20 @@ public static async Task DownloadLegacyTfToolsAsync(IExecutionContext executionC
{
executionContext.Debug($"vstsom-legacy download already exists at {vstsomLegacyExternalsPath}.");
}

string vstsHostLegacyExternalsPath = Path.Combine(externalsPath, "vstshost-legacy");

if (!Directory.Exists(vstsHostLegacyExternalsPath))
{
const string vstsHostDownloadUrl = "https://vstsagenttools.blob.core.windows.net/tools/vstshost/m122_887c6659/vstshost.zip";
string tempVstsHostDirectory = Path.Combine(externalsPath, "vstshost_download_temp");

await DownloadAsync(executionContext, vstsHostDownloadUrl, tempVstsHostDirectory, vstsHostLegacyExternalsPath, retryOptions);
}
else
{
executionContext.Debug($"vstshost-legacy download already exists at {vstsHostLegacyExternalsPath}.");
}
}

public static async Task DownloadAsync(IExecutionContext executionContext, string blobUrl, string tempDirectory, string extractPath, IRetryOptions retryOptions)
Expand Down
4 changes: 3 additions & 1 deletion src/Microsoft.VisualStudio.Services.Agent/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public enum WellKnownDirectory
Update,
Work,
TfLegacy,
ServerOMLegacy
ServerOMLegacy,
LegacyPSHostLegacy
}

public enum WellKnownConfigFile
Expand Down Expand Up @@ -314,6 +315,7 @@ public static class Path
public static readonly string DiagDirectory = "_diag";
public static readonly string ExternalsDirectory = "externals";
public static readonly string LegacyPSHostDirectory = "vstshost";
public static readonly string LegacyPSHostLegacyDirectory = "vstshost-legacy";
public static readonly string ServerOMDirectory = "vstsom";
public static readonly string ServerOMLegacyDirectory = "vstsom-legacy";
public static readonly string TempDirectory = "_temp";
Expand Down
6 changes: 6 additions & 0 deletions src/Microsoft.VisualStudio.Services.Agent/HostContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ public virtual string GetDirectory(WellKnownDirectory directory)
Constants.Path.LegacyPSHostDirectory);
break;

case WellKnownDirectory.LegacyPSHostLegacy:
path = Path.Combine(
GetDirectory(WellKnownDirectory.Externals),
Constants.Path.LegacyPSHostLegacyDirectory);
break;

case WellKnownDirectory.Root:
path = new DirectoryInfo(GetDirectory(WellKnownDirectory.Bin)).Parent.FullName;
break;
Expand Down
2 changes: 1 addition & 1 deletion src/Misc/externals.sh
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ if [[ "$PACKAGERUNTIME" == "win-x"* ]]; then
BIT="64"

acquireExternalTool "$CONTAINER_URL/azcopy/1/azcopy.zip" azcopy
acquireExternalTool "$CONTAINER_URL/vstshost/m122_887c6659/vstshost.zip" vstshost
acquireExternalTool "$CONTAINER_URL/vstshost/m122_887c6659_binding_redirect/vstshost.zip" vstshost
acquireExternalTool "$CONTAINER_URL/vstsom/m153_47c0856d_adhoc/vstsom.zip" vstsom
fi

Expand Down
6 changes: 6 additions & 0 deletions src/Test/L0/TestHostContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ public string GetDirectory(WellKnownDirectory directory)
Constants.Path.LegacyPSHostDirectory);
break;

case WellKnownDirectory.LegacyPSHostLegacy:
path = Path.Combine(
GetDirectory(WellKnownDirectory.Externals),
Constants.Path.LegacyPSHostLegacyDirectory);
break;

case WellKnownDirectory.Root:
path = new DirectoryInfo(GetDirectory(WellKnownDirectory.Bin)).Parent.FullName;
break;
Expand Down
7 changes: 7 additions & 0 deletions src/Test/L0/Worker/TfManagerL0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public sealed class TfManagerL0
{
private const string VstsomLegacy = "vstsom-legacy";
private const string TfLegacy = "tf-legacy";
private const string VstsHostLegacy = "vstshost-legacy";

[Fact]
[Trait("Level", "L0")]
Expand All @@ -34,6 +35,7 @@ public async Task DownloadTfLegacyToolsAsync()
string externalsPath = hostContext.GetDirectory(WellKnownDirectory.Externals);
string tfPath = Path.Combine(externalsPath, TfLegacy);
string vstsomPath = Path.Combine(externalsPath, VstsomLegacy);
string vstsHostPath = Path.Combine(externalsPath, VstsHostLegacy);

// Act
await TfManager.DownloadLegacyTfToolsAsync(executionContext.Object);
Expand All @@ -47,9 +49,14 @@ public async Task DownloadTfLegacyToolsAsync()
Assert.True(File.Exists(Path.Combine(vstsomPath, "TF.exe")));
Assert.False(Directory.Exists(Path.Combine(externalsPath, "vstsom_download_temp")));

Assert.True(Directory.Exists(vstsHostPath));
Assert.True(File.Exists(Path.Combine(vstsHostPath, "LegacyVSTSPowerShellHost.exe")));
Assert.False(Directory.Exists(Path.Combine(externalsPath, "vstshost_download_temp")));

// Cleanup
IOUtil.DeleteDirectory(tfPath, CancellationToken.None);
IOUtil.DeleteDirectory(vstsomPath, CancellationToken.None);
IOUtil.DeleteDirectory(vstsHostPath, CancellationToken.None);
}

[Fact]
Expand Down

0 comments on commit fa94da5

Please sign in to comment.