/// <summary> /// Insertable builds have valid artifacts and are not marked as 'DoesNotRequireInsertion_[TargetBranchName]'. /// </summary> private static async Task <List <Build> > GetInsertableBuildsAsync( BuildHttpClient buildClient, CancellationToken cancellationToken, IEnumerable <Build> builds) { List <Build> buildsWithValidArtifacts = new List <Build>(); foreach (var build in builds) { if (build.Tags?.Contains($"DoesNotRequireInsertion_{Options.VisualStudioBranchName}") == true) { continue; } // The artifact name passed to PublishBuildArtifacts task: var arcadeArtifactName = ArcadeInsertionArtifacts.ArtifactName; var legacyArtifactName = LegacyInsertionArtifacts.GetArtifactName(build.BuildNumber); var artifacts = await buildClient.GetArtifactsAsync(build.Project.Id, build.Id, cancellationToken); if (artifacts.Any(a => a.Name == arcadeArtifactName || a.Name == legacyArtifactName)) { buildsWithValidArtifacts.Add(build); } } return(buildsWithValidArtifacts); }
internal static async Task <InsertionArtifacts> GetInsertionArtifactsAsync(Build build, CancellationToken cancellationToken) { // used for local testing: if (LegacyInsertionArtifacts.TryCreateFromLocalBuild(Options.BuildDropPath, out var artifacts) || ArcadeInsertionArtifacts.TryCreateFromLocalBuild(Options.BuildDropPath, out artifacts)) { return(artifacts); } var buildClient = ProjectCollection.GetClient <BuildHttpClient>(); Debug.Assert(ReferenceEquals(build, (await GetInsertableBuildsAsync(buildClient, cancellationToken, new[] { build })).Single())); // Pull the VSSetup directory from artifacts store. var buildArtifacts = await buildClient.GetArtifactsAsync(build.Project.Id, build.Id, cancellationToken); // The artifact name passed to PublishBuildArtifacts task: var arcadeArtifactName = ArcadeInsertionArtifacts.ArtifactName; var legacyArtifactName = LegacyInsertionArtifacts.GetArtifactName(build.BuildNumber); foreach (var artifact in buildArtifacts) { if (artifact.Name == arcadeArtifactName) { // artifact.Resource.Data should be available and non-null due to BuildWithValidArtifactsAsync, // which checks this precondition if (!StringComparer.OrdinalIgnoreCase.Equals(artifact.Resource.Type, "container")) { throw new InvalidOperationException($"Could not find artifact '{arcadeArtifactName}' associated with build '{build.Id}'"); } return(new ArcadeInsertionArtifacts(await DownloadArtifactsAsync(buildClient, build, artifact, cancellationToken))); } else if (artifact.Name == legacyArtifactName) { // artifact.Resource.Data should be available and non-null due to BuildWithValidArtifactsAsync, // which checks this precondition if (string.Compare(artifact.Resource.Type, "container", StringComparison.OrdinalIgnoreCase) == 0) { // This is a build where the artifacts are published to the artifacts server instead of a UNC path. // Download this artifacts to a temp folder and provide that path instead. return(new LegacyInsertionArtifacts(await DownloadArtifactsAsync(buildClient, build, artifact, cancellationToken))); } return(new LegacyInsertionArtifacts(Path.Combine(artifact.Resource.Data, build.BuildNumber))); } } // Should never happen since we already filtered for containing valid paths throw new InvalidOperationException("Could not find drop path"); }