azure-sdk-for-net
azure-sdk-for-net copied to clipboard
[BUG] Parameter values not being passed to RunCommandAsync and RunCommandInput via RunCommandInputParameter
Library name and version
Azure.ResourceManager.Compute 1.10
Describe the bug
I have a PowerShell setup script I need to run as part of the setup before each test in our testing pipeline, the tests run as part of a DevOps pipeline on an Azure VM
We are using this to run our PowerShell scripts on the Azure VM, running the scripts without input.Parameters.Add(new RunCommandInputParameter(parameter, value));
works fine (we have another method to run scripts that is identical to this method but without the .Parameters.Add call)
public async Task RunPsFileWithParamAsync(string relativeScriptFilePath, string parameter, string value)
{
if (!relativeScriptFilePath.EndsWith(".ps1", StringComparison.InvariantCultureIgnoreCase)) throw new Exception($"{relativeScriptFilePath} must be a valid PowerShell file!");
string fullPath = Path.Combine(_scriptFileDirectory, relativeScriptFilePath);
var input = new RunCommandInput("RunPowerShellScript");
input.Parameters.Add(new RunCommandInputParameter(parameter, value));
input.Script.Add(fullPath);
foreach (var script in input.Script)
{
this._status.WriteLine($" - script file added: {script}");
}
foreach (var paramValuePair in input.Parameters)
{
this._status.WriteLine($" - parameter: {paramValuePair.Name} / {paramValuePair.Value}");
}
var result = await _vm.RunCommandAsync(WaitUntil.Completed, input);
if (!result.HasCompleted) throw new Exception("Error running script!");
this.HandleRunCommandOutput(result);
}
Expected behavior
When calling the method to run a script with params though, it'll say it added the param and value to my RunCommandInput but at runtime it doesn't look like any param values are actually being passed to the script
Actual behavior
The script runs but no values are actually passed to the script (script should been passed a 'true' value and should have thrown and printed the exception message, not the regular message)
Reproduction Steps
Initialize connection to Azure VirtualMachineResource / VM Create new RunCommandInput to run PowerShell script Add script to RunCommandInput Add parameter name-value pair to RunCommandInput Call RunCommandAsync with that RunCommandInput
Expected: Script should run w/ correct parameters
Actual: Script runs but no parameter values are passed to the script
Environment
OS Windows 10 .NET 7
Related
issue #30640 looks like someone else had an issue getting their parameters to pass too, I added my parameters like how they did aside from using the async version of RunCommand when they resolved their issue but haven't been able to get it to work yet
edit: also tried with the synchronous version of RunCommand, still not passing parameters to the script
Thank you for your feedback. Tagging and routing to the team member best able to assist.
@jvu-parsec ,Thank you for your feedback. The bug you mentioned has been fixed in the latest version. Regarding the issue you mentioned, I am not quite familiar with the role that the ‘throw’ statement plays in your script. I suggest that you optimize the script code and then continue your work on the latest version.
Hi @jvu-parsec. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.
Hi @jvu-parsec, we're sending this friendly reminder because we haven't heard back from you in 7 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!