public async Task AddTaskGroupSteps( BuildDefinition definition, CustomBuildDefinitionPayload payload) { var client = await _azureClient.GetTaskAgentAsync(); var taskGroups = await client.GetTaskGroupsAsync(ProvisioningProject); var amount = taskGroups.Count(x => x.Name.Equals(payload.BuildTemplate, StringComparison.CurrentCultureIgnoreCase)); if (amount > 1) { throw new Exception($"There are more than one TaskGroup with the name {payload.BuildTemplate} in the provisioning repository"); } if (amount == 0) { throw new Exception($"There is no TaskGroup with the name {payload.BuildTemplate} in the provisioning repository"); } var tg = taskGroups.FirstOrDefault(x => x.Name.Equals(payload.BuildTemplate, StringComparison.InvariantCultureIgnoreCase)); if (tg != null) { definition.Process = new DesignerProcess { Phases = { new Phase { Name = "Agent Job 1", RefName = "Job_1", Condition = "succeeded()", Steps = AddTasks(tg) } } }; definition.Properties.Add("tg_name", payload.BuildTemplate); } }
public async Task AddVariableGroups(BuildDefinition definition, CustomBuildDefinitionPayload payload) { if (payload.VariableGroups == null || payload.VariableGroups.Length == 0) { return; } var client = await _client.GetTaskAgentAsync(); foreach (var variableGroup in payload.VariableGroups) { var groups = await client.GetVariableGroupsAsync(project : payload.Project, groupName : variableGroup); if (groups == null || !groups.Any()) { throw new Exception($"Could not find any variablegroup with name: {variableGroup}"); } if (groups.Count() > 1) { throw new Exception($"There are more thant one variable group in the same project ({payload.Project}) with the same : {variableGroup}"); } var group = groups.FirstOrDefault(); if (group != null) { var g = new VariableGroup { Name = group.Name, Description = group.Description, Id = group.Id, Type = group.Type }; foreach (var(key, value) in group.Variables) { g.Variables[key] = new BuildDefinitionVariable { Value = value.Value, IsSecret = value.IsSecret }; } definition.VariableGroups.Add(g); } } }