public async Task AddTags(BuildDefinition definition, CustomBuildDefinitionPayload payload) { var client = await _client.GetBuildClientAsync(); await client.AddDefinitionTagsAsync(payload.Tags, payload.Project, definition.Id); }
public async Task GetTaskGroup(BuildDefinition definition, CustomBuildDefinitionPayload payload) { var buildClient = await _azureClient.GetBuildClientAsync(); var tgClient = await _azureClient.GetTaskAgentAsync(); var taskGroups = await tgClient.GetTaskGroupsAsync(ProvisioningProject); var props = await buildClient.GetDefinitionPropertiesAsync(project : payload.Project, definition.Id); if (props == null || !props.ContainsKey("tg_name")) { throw new Exception("Build definition does not have the metadata necessary"); } var tgName = props["tg_name"] as string; var amount = taskGroups.Count(x => x.Name.Equals(tgName, StringComparison.CurrentCultureIgnoreCase)); if (amount > 1) { throw new Exception($"There are more than one TaskGroup with the name {tgName} in the provisioning repository"); } if (amount == 0) { throw new Exception($"There is no TaskGroup with the name {tgName} in the provisioning repository"); } var tg = taskGroups.FirstOrDefault(x => x.Name.Equals(tgName, StringComparison.InvariantCultureIgnoreCase)); if (tg != null) { payload.BuildTemplate = tg.Name; payload.TaskGroupRevision = tg.Revision.ToString(); } }
public async Task <CustomBuildDefinitionPayload> GetAsync( string id) { try { var project = getProject(id); var buildId = getAdosId(id); var client = await _azureClient.GetBuildClientAsync(); var definitions = await client .GetFullDefinitionsAsync(project : project, definitionIds : new List <int> { Convert.ToInt32(buildId) }); if (definitions.Count > 1) { throw new Exception("Error: Found more thant one build with the same id"); } if (definitions.Count == 0) { throw new NotFoundException($"Error: Build wit ID: {buildId} not found"); } var result = definitions.FirstOrDefault(); if (result != null) { var appName = result.Name.Split('-'); var name = appName.Length == 0 ? $"Modified+{id}" : appName[0]; var definition = new CustomBuildDefinitionPayload { ApplicationName = name, Branch = result.Repository.DefaultBranch, Repository = result.Repository.Name, QueuePool = result.Queue.Name, BuildRevision = result.Revision.ToString(), Path = result.Path, Project = result.Project.Name, Tags = result.Tags.ToArray(), VariableGroups = result.VariableGroups.Select(x => x.Name).ToArray(), Variables = _variableService.GetVariables(result), CITriggers = new List <CITriggers> { _triggersService.GetCITriggers(result) }, ScheduleTriggers = _triggersService.GetScheduleTriggers(result) }; await _taskGroupService.GetTaskGroup(result, definition); return(definition); } return(null); } catch (NotFoundException) { throw; } catch (Exception e) { throw new Exception("Error: Something went wrong when calling the AzureDevOps API", e); } }