internal AssetData GetAssetDataWithLocations( string assetName, string assetVersion, string assetLocation1, LocationType assetLocationType1, string assetLocation2 = null, LocationType assetLocationType2 = LocationType.None) { var locationsListBuilder = ImmutableList.CreateBuilder <AssetLocationData>(); AssetLocationData location1 = new AssetLocationData(assetLocationType1) { Location = assetLocation1 }; locationsListBuilder.Add(location1); if (assetLocation2 != null && assetLocationType2 != LocationType.None) { AssetLocationData location2 = new AssetLocationData(assetLocationType2) { Location = assetLocation2 }; locationsListBuilder.Add(location2); } AssetData asset = new AssetData(false) { Name = assetName, Version = assetVersion, Locations = locationsListBuilder.ToImmutable() }; return(asset); }
internal AssetLocation(AssetLocationData other) { Location = other.Location; Type = (LocationType)(int)other.Type; }
public async Task <bool> PushMetadataAsync(CancellationToken cancellationToken) { try { cancellationToken.ThrowIfCancellationRequested(); Log.LogMessage(MessageImportance.High, "Starting build metadata push to the Build Asset Registry..."); if (!Directory.Exists(ManifestsPath)) { Log.LogError($"Required folder '{ManifestsPath}' does not exist."); } else { (List <BuildData> buildsManifestMetadata, List <SigningInformation> signingInformation, ManifestBuildData manifestBuildData) = GetBuildManifestsMetadata(ManifestsPath, cancellationToken); if (buildsManifestMetadata.Count == 0) { Log.LogError($"No build manifests found matching the search pattern {SearchPattern} in {ManifestsPath}"); return(!Log.HasLoggedErrors); } BuildData finalBuild = MergeBuildManifests(buildsManifestMetadata); IMaestroApi client = ApiFactory.GetAuthenticated(MaestroApiEndpoint, BuildAssetRegistryToken); var deps = await GetBuildDependenciesAsync(client, cancellationToken); Log.LogMessage(MessageImportance.High, "Calculated Dependencies:"); foreach (var dep in deps) { Log.LogMessage(MessageImportance.High, $" {dep.BuildId}, IsProduct: {dep.IsProduct}"); } finalBuild.Dependencies = deps; // Based on the in-memory merged manifest, create a physical XML file and // upload it to the BlobArtifacts folder only when publishingVersion >= 3 if (manifestBuildData.PublishingVersion >= 3) { SigningInformation finalSigningInfo = MergeSigningInfo(signingInformation); // Inject an entry of MergedManifest.xml to the in-memory merged manifest string location = null; AssetData assetData = finalBuild.Assets.FirstOrDefault(); if (assetData != null) { AssetLocationData assetLocationData = assetData.Locations.FirstOrDefault(); if (assetLocationData != null) { location = assetLocationData.Location; } } finalBuild.Assets = finalBuild.Assets.Add(GetManifestAsAsset(finalBuild.Assets, location, MergedManifestFileName)); BuildModel modelForManifest = CreateMergedManifestBuildModel(finalBuild.Assets, manifestBuildData); PushMergedManifest(modelForManifest, finalSigningInfo); } Client.Models.Build recordedBuild = await client.Builds.CreateAsync(finalBuild, cancellationToken); BuildId = recordedBuild.Id; Log.LogMessage(MessageImportance.High, $"Metadata has been pushed. Build id in the Build Asset Registry is '{recordedBuild.Id}'"); Console.WriteLine($"##vso[build.addbuildtag]BAR ID - {recordedBuild.Id}"); // Only 'create' the AzDO (VSO) variables if running in an AzDO build if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("BUILD_BUILDID"))) { IEnumerable <DefaultChannel> defaultChannels = await GetBuildDefaultChannelsAsync(client, recordedBuild); HashSet <int> targetChannelIds = new HashSet <int>(defaultChannels.Select(dc => dc.Channel.Id)); var defaultChannelsStr = "[" + string.Join("][", targetChannelIds) + "]"; Log.LogMessage(MessageImportance.High, $"Determined build will be added to the following channels: { defaultChannelsStr}"); Console.WriteLine($"##vso[task.setvariable variable=BARBuildId]{recordedBuild.Id}"); Console.WriteLine($"##vso[task.setvariable variable=DefaultChannels]{defaultChannelsStr}"); Console.WriteLine($"##vso[task.setvariable variable=IsStableBuild]{IsStableBuild}"); } } } catch (Exception exc) { Log.LogErrorFromException(exc, true, true, null); } return(!Log.HasLoggedErrors); }