From 5cb9c1775d5aacdf34be3dc6475e58ceac71c2c7 Mon Sep 17 00:00:00 2001 From: Kirill Ivlev <102740624+kirill-ivlev@users.noreply.github.com> Date: Fri, 19 May 2023 19:54:17 +0400 Subject: [PATCH] Fix PH `modifyEnvironment` (#4287) (#4288) * interim fix * Correct args line * Remove debug log Co-authored-by: Konstantin Tyukalov <52399739+KonstantinTyukalov@users.noreply.github.com> --- src/Agent.Worker/Handlers/ProcessHandler.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Agent.Worker/Handlers/ProcessHandler.cs b/src/Agent.Worker/Handlers/ProcessHandler.cs index b39c3d52eb..07e4f0e411 100644 --- a/src/Agent.Worker/Handlers/ProcessHandler.cs +++ b/src/Agent.Worker/Handlers/ProcessHandler.cs @@ -137,8 +137,8 @@ public async Task RunAsync() ? $"/c \"{_generatedScriptPath}" : $"/c \"{command} {arguments}"; - cmdExeArgs += _modifyEnvironment - ? " && echo {OutputDelimiter} && set \"" + cmdExeArgs += _modifyEnvironment && !enableSecureArguments + ? $" && echo {OutputDelimiter} && set \"" : "\""; // Invoke the process. @@ -211,9 +211,15 @@ private void GenerateScriptFile(string cmdExe, string command, string arguments) var agentTemp = ExecutionContext.GetVariableValueOrDefault(Constants.Variables.Agent.TempDirectory); _generatedScriptPath = Path.Combine(agentTemp, $"processHandlerScript_{scriptId}.cmd"); + var scriptArgs = $"/v:ON /c \"{command} !{inputArgsEnvVarName}!"; + + scriptArgs += _modifyEnvironment + ? $" && echo {OutputDelimiter} && set \"" + : "\""; + using (var writer = new StreamWriter(_generatedScriptPath)) { - writer.WriteLine($"{cmdExe} /v:ON /c \"{command} !{inputArgsEnvVarName}!\""); + writer.WriteLine($"{cmdExe} {scriptArgs}"); } ExecutionContext.Debug($"Generated script file: {_generatedScriptPath}");