Skip to content

Commit

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

* Correct args line

* Remove debug log
  • Loading branch information
KonstantinTyukalov authored May 19, 2023
1 parent 6e6a85c commit 809ce0e
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 809ce0e

Please sign in to comment.