Skip to content

Commit d7f4f8b

Browse files
authored
Fixed relative path failure in -AsJob scenario (#18307)
* Fixed relative path failure in -AsJob scenerio * fix typo
1 parent 0e1cec1 commit d7f4f8b

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

src/Resources/ResourceManager/Implementation/CmdletBase/ResourceWithParameterCmdletBase.cs

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,13 @@ public ITemplateSpecsClient TemplateSpecsClient
177177
set { this.templateSpecsClient = value; }
178178
}
179179

180+
protected override void OnBeginProcessing()
181+
{
182+
TemplateFile = this.TryResolvePath(TemplateFile);
183+
TemplateParameterFile = this.TryResolvePath(TemplateParameterFile);
184+
base.OnBeginProcessing();
185+
}
186+
180187
public new virtual object GetDynamicParameters()
181188
{
182189
if (BicepUtility.IsBicepFile(TemplateUri))
@@ -331,7 +338,7 @@ public ITemplateSpecsClient TemplateSpecsClient
331338
protected Hashtable GetTemplateParameterObject(Hashtable templateParameterObject)
332339
{
333340
// NOTE(jogao): create a new Hashtable so that user can re-use the templateParameterObject.
334-
var prameterObject = new Hashtable();
341+
var parameterObject = new Hashtable();
335342
if (templateParameterObject != null)
336343
{
337344
foreach (var parameterKey in templateParameterObject.Keys)
@@ -340,21 +347,24 @@ protected Hashtable GetTemplateParameterObject(Hashtable templateParameterObject
340347
var hashtableParameter = templateParameterObject[parameterKey] as Hashtable;
341348
if (hashtableParameter != null && hashtableParameter.ContainsKey("reference"))
342349
{
343-
prameterObject[parameterKey] = templateParameterObject[parameterKey];
350+
parameterObject[parameterKey] = templateParameterObject[parameterKey];
344351
}
345352
else
346353
{
347-
prameterObject[parameterKey] = new Hashtable { { "value", templateParameterObject[parameterKey] } };
354+
parameterObject[parameterKey] = new Hashtable { { "value", templateParameterObject[parameterKey] } };
348355
}
349356
}
350357
}
351358

352359
// Load parameters from the file
353360
string templateParameterFilePath = this.ResolvePath(TemplateParameterFile);
354-
if (templateParameterFilePath != null && FileUtilities.DataStore.FileExists(templateParameterFilePath))
361+
if (templateParameterFilePath != null)
355362
{
356-
var parametersFromFile = TemplateUtility.ParseTemplateParameterFileContents(templateParameterFilePath);
357-
parametersFromFile.ForEach(dp =>
363+
// Check whether templateParameterFilePath exists
364+
if (FileUtilities.DataStore.FileExists(templateParameterFilePath))
365+
{
366+
var parametersFromFile = TemplateUtility.ParseTemplateParameterFileContents(templateParameterFilePath);
367+
parametersFromFile.ForEach(dp =>
358368
{
359369
var parameter = new Hashtable();
360370
if (dp.Value.Value != null)
@@ -366,18 +376,25 @@ protected Hashtable GetTemplateParameterObject(Hashtable templateParameterObject
366376
parameter.Add("reference", dp.Value.Reference);
367377
}
368378

369-
prameterObject[dp.Key] = parameter;
379+
parameterObject[dp.Key] = parameter;
370380
});
371-
}
372381

382+
}
383+
else
384+
{
385+
// To not break previous behavior, just output a warning.
386+
WriteWarning("${templateParameterFilePath} does not exist");
387+
}
388+
}
389+
373390
// Load dynamic parameters
374391
IEnumerable<RuntimeDefinedParameter> parameters = PowerShellUtilities.GetUsedDynamicParameters(this.AsJobDynamicParameters, MyInvocation);
375392
if (parameters.Any())
376393
{
377-
parameters.ForEach(dp => prameterObject[((ParameterAttribute)dp.Attributes[0]).HelpMessage] = new Hashtable { { "value", dp.Value } });
394+
parameters.ForEach(dp => parameterObject[((ParameterAttribute)dp.Attributes[0]).HelpMessage] = new Hashtable { { "value", dp.Value } });
378395
}
379396

380-
return prameterObject;
397+
return parameterObject;
381398
}
382399

383400
protected string GetDeploymentDebugLogLevel(string deploymentDebugLogLevel)

src/Resources/Resources/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-->
2020

2121
## Upcoming Release
22+
* Fixed relative path failure in -AsJob scenario [#18084]
2223
* Fixed logic of `createtime` and `ChangedTime` in `Get-AzResource --ExpandProperties`. [#18206]
2324

2425
## Version 6.0.0

0 commit comments

Comments
 (0)