public async Task <IEnumerable <string> > GetSuggestionsAsync(IComponentConfiguration config) { var credentialName = config["CredentialName"]; var jobName = config["JobName"]; if (string.IsNullOrEmpty(credentialName) || string.IsNullOrEmpty(jobName)) { return(Enumerable.Empty <string>()); } var branchName = config["BranchName"]; string buildNumber = AH.CoalesceString(config["BuildNumber"], "lastSuccessfulBuild"); int?projectId = AH.ParseInt(AH.CoalesceString(config["ProjectId"], config["ApplicationId"])); int?environmentId = AH.ParseInt(config["EnvironmentId"]); var credentials = (JenkinsLegacyCredentials)ResourceCredentials.TryCreate(JenkinsLegacyCredentials.TypeName, credentialName, environmentId: environmentId, applicationId: projectId, inheritFromParent: false); if (credentials == null) { return(Enumerable.Empty <string>()); } using (var cts = new CancellationTokenSource(new TimeSpan(0, 0, 30))) { var client = new JenkinsClient(credentials.UserName, credentials.Password, credentials.ServerUrl, false, null, cts.Token); return((await client.GetBuildArtifactsAsync(jobName, branchName, buildNumber)) .Select(a => a.RelativePath) .ToList()); } }
public async Task <IEnumerable <string> > GetSuggestionsAsync(IComponentConfiguration config) { var credentialName = config["CredentialName"]; var jobName = config["JobName"]; if (string.IsNullOrEmpty(credentialName) || string.IsNullOrEmpty(jobName)) { return(Enumerable.Empty <string>()); } string buildNumber = AH.CoalesceString(config["BuildNumber"], "lastSuccessfulBuild"); var credentials = ResourceCredentials.Create <JenkinsCredentials>(credentialName); var client = new JenkinsClient(credentials); var artifacts = await client.GetBuildArtifactsAsync(jobName, buildNumber).ConfigureAwait(false); return(artifacts.Select(a => a.RelativePath)); }