Skip to content

Commit b2dc7c1

Browse files
authored
Merge pull request Azure#9184 from lwajswaj/bugfix/issue_8921
Update Start-AzAutomationDscNodeConfigurationDeployment to create a new JobId on each execution
2 parents cf4e9a1 + 18adfe1 commit b2dc7c1

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

src/Automation/Automation/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
* Changed behavior for Start-AzAutomationDscCompilationJob to just start the job instead of waiting for its completion.
2828
* Fix for issue https://github.com/Azure/azure-powershell/issues/8347
2929
* Fix for Get-AzAutomationDscNode when using -Name returns all node. Now it returns matching node only.
30+
* Fixed Start-AzAutomationDscNodeConfigurationDeployment cmdlet to allow multiple executions
3031

3132
## Version 1.2.1
3233
* Fixed New-AzAutomationSoftwareUpdateConfiguration cmdlet bug for Inclusions. Now parameter IncludedKbNumber and IncludedPackageNameMask should work.

src/Automation/Automation/Common/AutomationPSClientDSC.cs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,11 +1251,10 @@ public NodeConfigurationDeployment StartNodeConfigurationDeployment(string resou
12511251
Requires.Argument("NodeConfiguraionName", nodeConfiguraionName).NotNullOrEmpty().ValidNodeConfigurationName();
12521252

12531253
const string runbookName = "Deploy-NodeConfigurationToAutomationDscNodesV1";
1254+
System.Guid jobId = System.Guid.NewGuid();
12541255

1255-
IDictionary<string, string> processedParameters =
1256-
this.ProcessRunbookParameters(BuildParametersForNodeConfigurationDeploymentRunbook(),
1257-
ProcessParametersFornodeConfigurationRunbook(resourceGroupName, automationAccountName,
1258-
nodeConfiguraionName, nodeNames));
1256+
IDictionary<string, string> processedParameters = this.ProcessRunbookParameters(BuildParametersForNodeConfigurationDeploymentRunbook(),
1257+
ProcessParametersFornodeConfigurationRunbook(jobId, resourceGroupName, automationAccountName, nodeConfiguraionName, nodeNames));
12591258

12601259
JobSchedule jobSchedule = null;
12611260
Job job = null;
@@ -1265,7 +1264,7 @@ public NodeConfigurationDeployment StartNodeConfigurationDeployment(string resou
12651264
job = this.automationManagementClient.Job.Create(
12661265
resourceGroupName,
12671266
automationAccountName,
1268-
new Guid().ToString(),
1267+
jobId.ToString(),
12691268
new JobCreateParameters
12701269
{
12711270
Runbook = new RunbookAssociationProperty
@@ -1280,7 +1279,7 @@ public NodeConfigurationDeployment StartNodeConfigurationDeployment(string resou
12801279
jobSchedule = this.automationManagementClient.JobSchedule.Create(
12811280
resourceGroupName,
12821281
automationAccountName,
1283-
new Guid(),
1282+
jobId,
12841283
new JobScheduleCreateParameters
12851284
{
12861285
Schedule = new ScheduleAssociationProperty { Name = schedule.Name },
@@ -1592,7 +1591,7 @@ private Model.JobStream CreateJobStreamFromJobStreamModel(AutomationManagement.M
15921591
return new Model.JobStream(jobStream, resourceGroupName, automationAccountName, jobId);
15931592
}
15941593

1595-
private IDictionary<string, object> ProcessParametersFornodeConfigurationRunbook(string resourceGroup,
1594+
private IDictionary<string, object> ProcessParametersFornodeConfigurationRunbook(System.Guid jobId, string resourceGroup,
15961595
string automationAccountName, string nodeConfigurationName, string[][] nodeNames, int waitingPeriod = 0,
15971596
int numberOfAttempts = 0)
15981597
{
@@ -1604,6 +1603,7 @@ private IDictionary<string, object> ProcessParametersFornodeConfigurationRunbook
16041603
parameters.Add("AutomationAccountName", automationAccountName);
16051604
parameters.Add("NodeConfigurationName", nodeConfigurationName);
16061605
parameters.Add("ListOfNodeNames", nodeNames);
1606+
parameters.Add("Id", jobId.ToString());
16071607
}
16081608
catch (JsonSerializationException)
16091609
{
@@ -1629,44 +1629,51 @@ private IEnumerable<KeyValuePair<string, RunbookParameter>> BuildParametersForNo
16291629
{
16301630
var paramsForRunbook = new List<KeyValuePair<string, RunbookParameter>>
16311631
{
1632-
new KeyValuePair<string, RunbookParameter>("ResourceGroupName", new RunbookParameter
1632+
new KeyValuePair<string, RunbookParameter>("Id", new RunbookParameter
16331633
{
16341634
IsMandatory = true,
16351635
Position = 0,
16361636
DefaultValue = "",
1637+
Type = "System.Guid"
1638+
}),
1639+
new KeyValuePair<string, RunbookParameter>("ResourceGroupName", new RunbookParameter
1640+
{
1641+
IsMandatory = true,
1642+
Position = 1,
1643+
DefaultValue = "",
16371644
Type = "System.String"
16381645
}),
16391646
new KeyValuePair<string, RunbookParameter>("AutomationAccountName", new RunbookParameter
16401647
{
16411648
IsMandatory = true,
1642-
Position = 1,
1649+
Position = 2,
16431650
DefaultValue = "",
16441651
Type = "System.String"
16451652
}),
16461653
new KeyValuePair<string, RunbookParameter>("NodeConfigurationName", new RunbookParameter
16471654
{
16481655
IsMandatory = true,
1649-
Position = 2,
1656+
Position = 3,
16501657
DefaultValue = "",
16511658
Type = "System.String"
16521659
}),
16531660
new KeyValuePair<string, RunbookParameter>("ListOfNodeNames", new RunbookParameter
16541661
{
16551662
IsMandatory = true,
1656-
Position = 3,
1663+
Position = 4,
16571664
Type = "System.Array"
16581665
}),
16591666
new KeyValuePair<string, RunbookParameter>("WaitingPeriod", new RunbookParameter
16601667
{
16611668
IsMandatory = false,
1662-
Position = 4,
1669+
Position = 5,
16631670
DefaultValue = "60",
16641671
Type = "System.Int32"
16651672
}),
16661673
new KeyValuePair<string, RunbookParameter>("NumberOfTriesPerGroup", new RunbookParameter
16671674
{
16681675
IsMandatory = false,
1669-
Position = 5,
1676+
Position = 6,
16701677
DefaultValue = "100",
16711678
Type = "System.Int32"
16721679
})

0 commit comments

Comments
 (0)