Skip to content

Update Start-AzAutomationDscNodeConfigurationDeployment to create a new JobId on each execution #9184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Automation/Automation/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* Changed behavior for Start-AzAutomationDscCompilationJob to just start the job instead of waiting for its completion.
* Fix for issue https://github.com/Azure/azure-powershell/issues/8347
* Fix for Get-AzAutomationDscNode when using -Name returns all node. Now it returns matching node only.
* Fixed Start-AzAutomationDscNodeConfigurationDeployment cmdlet to allow multiple executions

## Version 1.2.1
* Fixed New-AzAutomationSoftwareUpdateConfiguration cmdlet bug for Inclusions. Now parameter IncludedKbNumber and IncludedPackageNameMask should work.
Expand Down
33 changes: 20 additions & 13 deletions src/Automation/Automation/Common/AutomationPSClientDSC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1251,11 +1251,10 @@ public NodeConfigurationDeployment StartNodeConfigurationDeployment(string resou
Requires.Argument("NodeConfiguraionName", nodeConfiguraionName).NotNullOrEmpty().ValidNodeConfigurationName();

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

IDictionary<string, string> processedParameters =
this.ProcessRunbookParameters(BuildParametersForNodeConfigurationDeploymentRunbook(),
ProcessParametersFornodeConfigurationRunbook(resourceGroupName, automationAccountName,
nodeConfiguraionName, nodeNames));
IDictionary<string, string> processedParameters = this.ProcessRunbookParameters(BuildParametersForNodeConfigurationDeploymentRunbook(),
ProcessParametersFornodeConfigurationRunbook(jobId, resourceGroupName, automationAccountName, nodeConfiguraionName, nodeNames));

JobSchedule jobSchedule = null;
Job job = null;
Expand All @@ -1265,7 +1264,7 @@ public NodeConfigurationDeployment StartNodeConfigurationDeployment(string resou
job = this.automationManagementClient.Job.Create(
resourceGroupName,
automationAccountName,
new Guid().ToString(),
jobId.ToString(),
new JobCreateParameters
{
Runbook = new RunbookAssociationProperty
Expand All @@ -1280,7 +1279,7 @@ public NodeConfigurationDeployment StartNodeConfigurationDeployment(string resou
jobSchedule = this.automationManagementClient.JobSchedule.Create(
resourceGroupName,
automationAccountName,
new Guid(),
jobId,
new JobScheduleCreateParameters
{
Schedule = new ScheduleAssociationProperty { Name = schedule.Name },
Expand Down Expand Up @@ -1592,7 +1591,7 @@ private Model.JobStream CreateJobStreamFromJobStreamModel(AutomationManagement.M
return new Model.JobStream(jobStream, resourceGroupName, automationAccountName, jobId);
}

private IDictionary<string, object> ProcessParametersFornodeConfigurationRunbook(string resourceGroup,
private IDictionary<string, object> ProcessParametersFornodeConfigurationRunbook(System.Guid jobId, string resourceGroup,
string automationAccountName, string nodeConfigurationName, string[][] nodeNames, int waitingPeriod = 0,
int numberOfAttempts = 0)
{
Expand All @@ -1604,6 +1603,7 @@ private IDictionary<string, object> ProcessParametersFornodeConfigurationRunbook
parameters.Add("AutomationAccountName", automationAccountName);
parameters.Add("NodeConfigurationName", nodeConfigurationName);
parameters.Add("ListOfNodeNames", nodeNames);
parameters.Add("Id", jobId.ToString());
}
catch (JsonSerializationException)
{
Expand All @@ -1629,44 +1629,51 @@ private IEnumerable<KeyValuePair<string, RunbookParameter>> BuildParametersForNo
{
var paramsForRunbook = new List<KeyValuePair<string, RunbookParameter>>
{
new KeyValuePair<string, RunbookParameter>("ResourceGroupName", new RunbookParameter
new KeyValuePair<string, RunbookParameter>("Id", new RunbookParameter
{
IsMandatory = true,
Position = 0,
DefaultValue = "",
Type = "System.Guid"
}),
new KeyValuePair<string, RunbookParameter>("ResourceGroupName", new RunbookParameter
{
IsMandatory = true,
Position = 1,
DefaultValue = "",
Type = "System.String"
}),
new KeyValuePair<string, RunbookParameter>("AutomationAccountName", new RunbookParameter
{
IsMandatory = true,
Position = 1,
Position = 2,
DefaultValue = "",
Type = "System.String"
}),
new KeyValuePair<string, RunbookParameter>("NodeConfigurationName", new RunbookParameter
{
IsMandatory = true,
Position = 2,
Position = 3,
DefaultValue = "",
Type = "System.String"
}),
new KeyValuePair<string, RunbookParameter>("ListOfNodeNames", new RunbookParameter
{
IsMandatory = true,
Position = 3,
Position = 4,
Type = "System.Array"
}),
new KeyValuePair<string, RunbookParameter>("WaitingPeriod", new RunbookParameter
{
IsMandatory = false,
Position = 4,
Position = 5,
DefaultValue = "60",
Type = "System.Int32"
}),
new KeyValuePair<string, RunbookParameter>("NumberOfTriesPerGroup", new RunbookParameter
{
IsMandatory = false,
Position = 5,
Position = 6,
DefaultValue = "100",
Type = "System.Int32"
})
Expand Down