Skip to content

Commit

Permalink
Fix PH modifyEnvironment (#4287) (#4288)
Browse files Browse the repository at this point in the history
* interim fix

* Correct args line

* Remove debug log

Co-authored-by: Konstantin Tyukalov <52399739+KonstantinTyukalov@users.noreply.github.com>
  • Loading branch information
kirill-ivlev and KonstantinTyukalov authored May 19, 2023
1 parent 388026e commit 5cb9c17
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Agent.Worker/Handlers/ProcessHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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}");
Expand Down

0 comments on commit 5cb9c17

Please sign in to comment.