Skip to content

Commit

Permalink
Add AZP_AGENT_CLEANUP_PSMODULES_IN_POWERSHELL agent knob (#4360)
Browse files Browse the repository at this point in the history
* add knob agent in pwsh

* rename knob
  • Loading branch information
DenisRumyantsev authored Jul 18, 2023
1 parent 895e73a commit 3517c9f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/Agent.Sdk/Knob/AgentKnobs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -486,5 +486,12 @@ public class AgentKnobs
new RuntimeKnobSource("AGENT_FORCE_CREATE_TASKS_DIRECTORY"),
new EnvironmentKnobSource("AGENT_FORCE_CREATE_TASKS_DIRECTORY"),
new BuiltInDefaultKnobSource("false"));

public static readonly Knob CleanupPSModules = new Knob(
nameof(CleanupPSModules),
"Removes the PSModulePath environment variable if the agent is running in PowerShell.",
new RuntimeKnobSource("AZP_AGENT_CLEANUP_PSMODULES_IN_POWERSHELL"),
new EnvironmentKnobSource("AZP_AGENT_CLEANUP_PSMODULES_IN_POWERSHELL"),
new BuiltInDefaultKnobSource("false"));
}
}
3 changes: 2 additions & 1 deletion src/Agent.Worker/Handlers/Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,8 @@ protected void AddPrependPathToEnvironment()

protected void RemovePSModulePathFromEnvironment()
{
if (PlatformUtil.RunningOnWindows && WindowsProcessUtil.AgentIsRunningInPowerShell())
if (AgentKnobs.CleanupPSModules.GetValue(ExecutionContext).AsBoolean() &&
PlatformUtil.RunningOnWindows && WindowsProcessUtil.AgentIsRunningInPowerShell())
{
AddEnvironmentVariable("PSModulePath", "");
Trace.Info("PSModulePath removed from environment since agent is running on Windows and in PowerShell.");
Expand Down

0 comments on commit 3517c9f

Please sign in to comment.