Hi Hendrik,
(Zie het bijgevoegde bestand: StepTemplate.json)
Thanks for the effort to contact me. Herewith the troubled StepTemplate.
Herewith also a part of the code, the code uses an existing process. That process contains a step (with the name TemplateStep and uses the troubled steptempate), all the generated steps are based on the template step.
Kind regards,
Barend Tempelman
OctopusRepository repo = new OctopusRepository(client);
ProjectResource project = repo.Projects.FindByName(“MyProject”);
DeploymentProcessResource process = repo.DeploymentProcesses.Get(project.DeploymentProcessId);
VariableSetResource varset = repo.VariableSets.Get(project.VariableSetId);
List environments = repo.Environments.FindAll();
DeploymentStepResource templateStep = process.Steps.Where(t => t.Name.Equals(“TemplateStepThatUsesTheTroubledStepTemplate”, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
if (templateStep == null)
{
MessageBox.Show("TemplateStep not found");
return null;
}
//create steps
assisoReadResult.GroupBy(x => StepFilter.GetMainStepName(x.StapName, x.TargetRoles)).Select(grp => new KeyValuePair<string, string>(grp.First().StapName, grp.First().TargetRoles)).ToList()
.ForEach(r => stepResult.StepsToExecute.Add(new StepResult(StepFilter.GetMainStepName(r.Key, r.Value), r.Value)));
foreach (SqlStepTemplate item in assisoReadResult)
{
string databaseName = item.TemplateType == EStepTemplateType.SqlCreateLogin ? "master" : item.DatabaseName;
SubStep ss = new SubStep(item.StapName, item.DatabaseServerName, databaseName, item.GetCmdVariables, item.ScriptPad);
stepResult.AddToResult(ss, StepFilter.GetMainStepName(item.StapName, item.TargetRoles));
}
foreach (StepResult item in stepResult.StepsToExecute)
{
DeploymentStepResource nieuwe = new DeploymentStepResource();
nieuwe.Name = $"Uitvoeren scripts {item.TaskName}";
nieuwe.Condition = templateStep.Condition;
foreach (var prop in templateStep.Properties)
{
if (prop.Key.Equals("Octopus.Action.TargetRoles"))
{
nieuwe.Properties.Add(prop.Key, new PropertyValueResource(item.MachineRoleName, prop.Value.IsSensitive));
}
else
{
nieuwe.Properties.Add(prop);
}
}
foreach (var act in templateStep.Actions)
{
DeploymentActionResource res = new DeploymentActionResource
{
Name = $"Uitvoeren scripts {item.TaskName}",
ActionType = act.ActionType,
CanBeUsedForProjectVersioning = act.CanBeUsedForProjectVersioning,
IsDisabled = false,
IsRequired = act.IsRequired,
WorkerPoolId = act.WorkerPoolId,
LastModifiedBy = "Tooltje",
LastModifiedOn = DateTime.Now
};
bool isPropFound = false;
foreach (var prop in act.Properties)
{
switch (prop.Key)
{
//I'll set my value here to the SqlCommandSet param, otherwise I just add the template from the TemplateStep
case "SqlCommandSet":
{
isPropFound = true;
res.Properties.Add(prop.Key, new PropertyValueResource(item.ToString(), false));
break;
}
default:
{
res.Properties.Add(prop);
break;
}
}
}
//THIS IS MY FIX, IF THE PROPERTY IS NOT FOUND, I'LL ADD IT THE HARD WAY
if (!isPropFound)
{ res.Properties.Add("SqlCommandSet", new PropertyValueResource(item.ToString(), false)); }
foreach (var ex in act.ExcludedEnvironments)
{
res.ExcludedEnvironments.Add(ex);
}
foreach (var ex in act.Channels)
{
res.Channels.Add(ex);
}
foreach (var ex in act.TenantTags)
{
res.TenantTags.Add(ex);
}
nieuwe.Actions.Add(res);
}
process.Steps.Add(nieuwe);
}
repo.DeploymentProcesses.Modify(process);
“Henrik Andersson” —01/29/2019 03:48:13 AM—Hi there, Thanks for getting in touch.
StepTemplate.json (2.99 KB)