public async Task <IEnumerable <string> > GetSuggestionsAsync(IComponentConfiguration config) { var credentialName = config["CredentialName"]; var projectName = AH.CoalesceString(config["TeamProject"], config["TeamProjectName"]); var definitionName = config["BuildDefinition"]; if (string.IsNullOrEmpty(credentialName) || string.IsNullOrEmpty(projectName) || string.IsNullOrEmpty(definitionName)) { return(Enumerable.Empty <string>()); } var credentials = ResourceCredentials.Create <TfsCredentials>(credentialName); var api = new TfsRestApi(credentials, null); var definition = await api.GetBuildDefinitionAsync(projectName, definitionName).ConfigureAwait(false); if (definition == null) { return(Enumerable.Empty <string>()); } var builds = await api.GetBuildsAsync(projectName, definition.id).ConfigureAwait(false); return(builds.Select(b => b.buildNumber)); }
public override async Task <IEnumerable <string> > EnumerateValuesAsync(ValueEnumerationContext context) { var credentials = ResourceCredentials.Create <TfsCredentials>(this.CredentialName); var api = new TfsRestApi(credentials, null); var definition = await api.GetBuildDefinitionAsync(this.TeamProjectName, this.BuildDefinitionName).ConfigureAwait(false); if (definition == null) { return(Enumerable.Empty <string>()); } var builds = await api.GetBuildsAsync(this.TeamProjectName, definition.id).ConfigureAwait(false); return(builds.Select(b => b.buildNumber)); }
public async Task <TfsArtifact> DownloadAsync(string teamProject, string buildNumber, string buildDefinitionName, string artifactName) { if (string.IsNullOrEmpty(teamProject)) { throw new ArgumentException("A team project is required to download the artifact.", nameof(teamProject)); } if (string.IsNullOrEmpty(artifactName)) { throw new ArgumentException("An artifact name is required to download the artifact.", nameof(artifactName)); } var api = new TfsRestApi(connectionInfo, logger); var buildDefinition = await api.GetBuildDefinitionAsync(teamProject, buildDefinitionName).ConfigureAwait(false); if (buildDefinition == null) { throw new InvalidOperationException($"The build definition {buildDefinitionName} could not be found."); } logger.LogInformation($"Finding {AH.CoalesceString(buildNumber, "last successful")} build..."); var builds = await api.GetBuildsAsync( project : teamProject, buildDefinition : buildDefinition.id, buildNumber : AH.NullIf(buildNumber, ""), resultFilter : "succeeded", statusFilter : "completed", top : 2 ).ConfigureAwait(false); if (builds.Length == 0) { throw new InvalidOperationException($"Could not find build number {buildNumber}. Ensure there is a successful, completed build with this number."); } var build = builds.FirstOrDefault(); logger.LogInformation($"Downloading {artifactName} artifact from VSO..."); var stream = await api.DownloadArtifactAsync(teamProject, build.id, artifactName).ConfigureAwait(false); return(new TfsArtifact(stream, artifactName, buildNumber)); }
public async Task <IEnumerable <string> > GetSuggestionsAsync(IComponentConfiguration config) { var credentialName = config["CredentialName"]; var projectName = AH.CoalesceString(config["TeamProject"], config["TeamProjectName"]); var definitionName = config["BuildDefinition"]; if (string.IsNullOrEmpty(credentialName) || string.IsNullOrEmpty(projectName) || string.IsNullOrEmpty(definitionName)) { return(Enumerable.Empty <string>()); } var buildNumber = config["BuildNumber"]; var credentials = ResourceCredentials.Create <TfsCredentials>(credentialName); var api = new TfsRestApi(credentials, null); var definition = await api.GetBuildDefinitionAsync(projectName, definitionName).ConfigureAwait(false); if (definition == null) { return(Enumerable.Empty <string>()); } var builds = await api.GetBuildsAsync( project : projectName, buildDefinition : definition.id, buildNumber : AH.NullIf(buildNumber, ""), resultFilter : "succeeded", statusFilter : "completed", top : 2 ).ConfigureAwait(false); var build = builds.FirstOrDefault(); if (build == null) { return(Enumerable.Empty <string>()); } var artifacts = await api.GetArtifactsAsync(projectName, build.id).ConfigureAwait(false); return(artifacts.Select(a => a.name)); }