public PublishArtifactsInManifestBase WhichPublishingTask(string manifestFullPath) { Log.LogMessage(MessageImportance.High, $"Creating a task to publish assets from {manifestFullPath}"); if (!File.Exists(manifestFullPath)) { Log.LogError($"Problem reading asset manifest path from '{manifestFullPath}'"); return(null); } BuildModel buildModel = BuildManifestUtil.ManifestFileToModel(manifestFullPath, Log); if (buildModel.Identity.PublishingVersion == PublishingInfraVersion.Legacy) { Log.LogError("This task is not able to handle legacy manifests."); return(null); } else if (buildModel.Identity.PublishingVersion == PublishingInfraVersion.Latest) { return(ConstructPublishingV2Task(buildModel)); } else if (buildModel.Identity.PublishingVersion == PublishingInfraVersion.Next) { return(ConstructPublishingV3Task(buildModel)); } else { Log.LogError($"The manifest version '{buildModel.Identity.PublishingVersion}' is not recognized by the publishing task."); return(null); } }
public static BuildModel CreateModelFromItems( ITaskItem[] artifacts, string buildId, string[] BuildProperties, string repoUri, string repoBranch, string repoCommit, bool isStableBuild, string publishingVersion, TaskLoggingHelper log) { if (artifacts == null) { throw new ArgumentNullException(nameof(artifacts)); } var blobArtifacts = new List <BlobArtifactModel>(); var packageArtifacts = new List <PackageArtifactModel>(); foreach (var artifact in artifacts) { if (string.Equals(artifact.GetMetadata("ExcludeFromManifest"), "true", StringComparison.OrdinalIgnoreCase)) { continue; } var isSymbolsPackage = artifact.ItemSpec.EndsWith(".symbols.nupkg", StringComparison.OrdinalIgnoreCase) || artifact.ItemSpec.EndsWith(".snupkg", StringComparison.OrdinalIgnoreCase); if (artifact.ItemSpec.EndsWith(".nupkg", StringComparison.OrdinalIgnoreCase) && !isSymbolsPackage) { packageArtifacts.Add(BuildManifestUtil.CreatePackageArtifactModel(artifact)); } else { if (isSymbolsPackage) { string fileName = Path.GetFileName(artifact.ItemSpec); artifact.SetMetadata("RelativeBlobPath", $"{BuildManifestUtil.AssetsVirtualDir}symbols/{fileName}"); } blobArtifacts.Add(BuildManifestUtil.CreateBlobArtifactModel(artifact)); } } var buildModel = BuildManifestUtil.CreateModel( blobArtifacts, packageArtifacts, buildId, BuildProperties, repoUri, repoBranch, repoCommit, isStableBuild, publishingVersion, log); return(buildModel); }
private IEnumerable <BlobArtifactModel> ConcatBlobArtifacts( IEnumerable <BlobArtifactModel> artifacts, IEnumerable <ITaskItem> items) { return(artifacts.Concat(items .Where(i => !string.Equals(i.GetMetadata("ExcludeFromManifest"), "true", StringComparison.OrdinalIgnoreCase)) .Select(i => BuildManifestUtil.CreateBlobArtifactModel(i, Log)) .Where(blob => blob != null))); }
public async Task <bool> ExecuteAsync() { try { Log.LogMessage(MessageImportance.High, "Publishing artifacts to feed."); if (string.IsNullOrWhiteSpace(AssetManifestPath) || !File.Exists(AssetManifestPath)) { Log.LogError($"Problem reading asset manifest path from '{AssetManifestPath}'"); } if (!Directory.Exists(BlobAssetsBasePath)) { Log.LogError($"Problem reading blob assets from {BlobAssetsBasePath}"); } if (!Directory.Exists(PackageAssetsBasePath)) { Log.LogError($"Problem reading package assets from {PackageAssetsBasePath}"); } var buildModel = BuildManifestUtil.ManifestFileToModel(AssetManifestPath, Log); // Parsing the manifest may fail for several reasons if (Log.HasLoggedErrors) { return(false); } // Fetch Maestro record of the build. We're going to use it to get the BAR ID // of the assets being published so we can add a new location for them. IMaestroApi client = ApiFactory.GetAuthenticated(MaestroApiEndpoint, BuildAssetRegistryToken); Maestro.Client.Models.Build buildInformation = await client.Builds.GetBuildAsync(BARBuildId); ParseTargetFeedConfig(); // Return errors from parsing FeedConfig if (Log.HasLoggedErrors) { return(false); } SplitArtifactsInCategories(buildModel); await HandlePackagePublishingAsync(client, buildInformation); await HandleBlobPublishingAsync(client, buildInformation); } catch (Exception e) { Log.LogErrorFromException(e, true); } return(!Log.HasLoggedErrors); }
public override bool Execute() { try { var buildModel = BuildManifestUtil.CreateModelFromItems(Artifacts, BuildId, BuildData, RepoUri, RepoBranch, RepoCommit, Log); buildModel.WriteAsXml(OutputPath, Log); } catch (Exception e) { Log.LogErrorFromException(e, true); } return(!Log.HasLoggedErrors); }
public override bool Execute() { try { PublishingInfraVersion targetPublishingVersion = PublishingInfraVersion.Legacy; if (!string.IsNullOrEmpty(PublishingVersion)) { if (Enum.TryParse(PublishingVersion, ignoreCase: true, out targetPublishingVersion)) { Log.LogError($"Could not parse '{PublishingVersion}' as a valid publishing infrastructure version."); return(false); } } var buildModel = BuildManifestUtil.CreateModelFromItems( Artifacts, AzureDevOpsCollectionUri, AzureDevOpsProject, AzureDevOpsBuildId, ItemsToSign, StrongNameSignInfo, FileSignInfo, FileExtensionSignInfo, CertificatesSignInfo, BuildId, BuildData, RepoUri, RepoBranch, RepoCommit, IsStableBuild, targetPublishingVersion, IsReleaseOnlyPackageVersion, Log); buildModel.WriteAsXml(OutputPath, Log); } catch (Exception e) { Log.LogErrorFromException(e, true); } return(!Log.HasLoggedErrors); }
public override bool Execute() { Log.LogMessage(MessageImportance.High, "Parsing build manifest file: {0}", AssetManifestPath); try { BuildModel buildModel = BuildManifestUtil.ManifestFileToModel(AssetManifestPath, Log); if (!Log.HasLoggedErrors) { if (buildModel.Artifacts.Blobs.Any()) { BlobInfos = buildModel.Artifacts.Blobs.Select(blob => new MSBuild.TaskItem(blob.Id)).ToArray(); } if (buildModel.Artifacts.Packages.Any()) { PackageInfos = buildModel.Artifacts.Packages.Select(ConvertToPackageInfoItem).ToArray(); } } } catch (Exception e) { Log.LogErrorFromException(e, true); } return(!Log.HasLoggedErrors); }
public async Task <bool> ExecuteAsync() { try { Log.LogMessage(MessageImportance.High, "Performing push feeds."); if (string.IsNullOrWhiteSpace(ExpectedFeedUrl) || string.IsNullOrWhiteSpace(AccountKey)) { Log.LogError($"{nameof(ExpectedFeedUrl)} / {nameof(AccountKey)} is not set properly."); } else if (string.IsNullOrWhiteSpace(AssetManifestPath) || !File.Exists(AssetManifestPath)) { Log.LogError($"Problem reading asset manifest path from {AssetManifestPath}"); } else if (MaxClients <= 0) { Log.LogError($"{nameof(MaxClients)} should be greater than zero."); } else if (UploadTimeoutInMinutes <= 0) { Log.LogError($"{nameof(UploadTimeoutInMinutes)} should be greater than zero."); } var buildModel = BuildManifestUtil.ManifestFileToModel(AssetManifestPath, Log); // Parsing the manifest may fail for several reasons if (Log.HasLoggedErrors) { return(false); } // Fetch Maestro record of the build. We're going to use it to get the BAR ID // of the assets being published so we can add a new location for them. IMaestroApi client = ApiFactory.GetAuthenticated(MaestroApiEndpoint, BuildAssetRegistryToken); Maestro.Client.Models.Build buildInformation = await client.Builds.GetBuildAsync(BARBuildId); var blobFeedAction = new BlobFeedAction(ExpectedFeedUrl, AccountKey, Log); var pushOptions = new PushOptions { AllowOverwrite = Overwrite, PassIfExistingItemIdentical = PassIfExistingItemIdentical }; if (buildModel.Artifacts.Packages.Any()) { if (!Directory.Exists(PackageAssetsBasePath)) { Log.LogError($"Invalid {nameof(PackageAssetsBasePath)} was supplied: {PackageAssetsBasePath}"); return(false); } PackageAssetsBasePath = PackageAssetsBasePath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar) + Path.DirectorySeparatorChar; var packages = buildModel.Artifacts.Packages.Select(p => $"{PackageAssetsBasePath}{p.Id}.{p.Version}.nupkg"); await blobFeedAction.PushToFeedAsync(packages, pushOptions); foreach (var package in buildModel.Artifacts.Packages) { var assetRecord = buildInformation.Assets .Where(a => a.Name.Equals(package.Id) && a.Version.Equals(package.Version)) .Single(); if (assetRecord == null) { Log.LogError($"Asset with Id {package.Id}, Version {package.Version} isn't registered on the BAR Build with ID {BARBuildId}"); continue; } await client.Assets.AddAssetLocationToAssetAsync(assetRecord.Id.Value, ExpectedFeedUrl, "NugetFeed"); } } if (buildModel.Artifacts.Blobs.Any()) { if (!Directory.Exists(BlobAssetsBasePath)) { Log.LogError($"Invalid {nameof(BlobAssetsBasePath)} was supplied: {BlobAssetsBasePath}"); return(false); } BlobAssetsBasePath = BlobAssetsBasePath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar) + Path.DirectorySeparatorChar; var blobs = buildModel.Artifacts.Blobs .Select(blob => { var fileName = Path.GetFileName(blob.Id); return(new MSBuild.TaskItem($"{BlobAssetsBasePath}{fileName}", new Dictionary <string, string> { { "RelativeBlobPath", $"{BuildManifestUtil.AssetsVirtualDir}{blob.Id}" } })); }) .ToArray(); await blobFeedAction.PublishToFlatContainerAsync(blobs, MaxClients, UploadTimeoutInMinutes, pushOptions); foreach (var package in buildModel.Artifacts.Blobs) { var assetRecord = buildInformation.Assets .Where(a => a.Name.Equals(package.Id)) .SingleOrDefault(); if (assetRecord == null) { Log.LogError($"Asset with Id {package.Id} isn't registered on the BAR Build with ID {BARBuildId}"); continue; } await client.Assets.AddAssetLocationToAssetAsync(assetRecord.Id.Value, ExpectedFeedUrl, "NugetFeed"); } } } catch (Exception e) { Log.LogErrorFromException(e, true); } return(!Log.HasLoggedErrors); }
public override bool Execute() { try { Log.LogMessage(MessageImportance.High, "Performing push to Azure DevOps artifacts storage."); if (ItemsToPush == null) { Log.LogError($"No items to push. Please check ItemGroup ItemsToPush."); } else { IEnumerable <BlobArtifactModel> blobArtifacts = Enumerable.Empty <BlobArtifactModel>(); IEnumerable <PackageArtifactModel> packageArtifacts = Enumerable.Empty <PackageArtifactModel>(); if (PublishFlatContainer) { blobArtifacts = ItemsToPush.Select(BuildManifestUtil.CreateBlobArtifactModel).Where(blob => blob != null); } else { var itemsToPushNoExcludes = ItemsToPush. Where(i => !string.Equals(i.GetMetadata("ExcludeFromManifest"), "true", StringComparison.OrdinalIgnoreCase)); ITaskItem[] symbolItems = itemsToPushNoExcludes .Where(i => i.ItemSpec.Contains("symbols.nupkg")) .Select(i => { string fileName = Path.GetFileName(i.ItemSpec); i.SetMetadata("RelativeBlobPath", $"{BuildManifestUtil.AssetsVirtualDir}symbols/{fileName}"); return(i); }) .ToArray(); ITaskItem[] packageItems = itemsToPushNoExcludes .Where(i => !symbolItems.Contains(i)) .ToArray(); // To prevent conflicts with other parts of the build system that might move the artifacts // folder while the artifacts are still being published, we copy the artifacts to a temporary // location only for the sake of uploading them. This is a temporary solution and will be // removed in the future. if (!Directory.Exists(AssetsTemporaryDirectory)) { Log.LogMessage(MessageImportance.High, $"Assets temporary directory {AssetsTemporaryDirectory} doesn't exist. Creating it."); Directory.CreateDirectory(AssetsTemporaryDirectory); } foreach (var packagePath in packageItems) { var destFile = $"{AssetsTemporaryDirectory}/{Path.GetFileName(packagePath.ItemSpec)}"; File.Copy(packagePath.ItemSpec, destFile); Log.LogMessage(MessageImportance.High, $"##vso[artifact.upload containerfolder=PackageArtifacts;artifactname=PackageArtifacts]{destFile}"); } foreach (var symbolPath in symbolItems) { var destFile = $"{AssetsTemporaryDirectory}/{Path.GetFileName(symbolPath.ItemSpec)}"; File.Copy(symbolPath.ItemSpec, destFile); Log.LogMessage(MessageImportance.High, $"##vso[artifact.upload containerfolder=BlobArtifacts;artifactname=BlobArtifacts]{destFile}"); } packageArtifacts = packageItems.Select(BuildManifestUtil.CreatePackageArtifactModel); blobArtifacts = symbolItems.Select(BuildManifestUtil.CreateBlobArtifactModel).Where(blob => blob != null); } BuildManifestUtil.CreateBuildManifest(Log, blobArtifacts, packageArtifacts, AssetManifestPath, ManifestRepoUri, ManifestBuildId, ManifestBranch, ManifestCommit, ManifestBuildData); } } catch (Exception e) { Log.LogErrorFromException(e, true); } return(!Log.HasLoggedErrors); }
public static BuildModel CreateModelFromItems( ITaskItem[] artifacts, ITaskItem[] itemsToSign, ITaskItem[] strongNameSignInfo, ITaskItem[] fileSignInfo, ITaskItem[] fileExtensionSignInfo, ITaskItem[] certificatesSignInfo, string buildId, string[] manifestBuildData, string repoUri, string repoBranch, string repoCommit, bool isStableBuild, PublishingInfraVersion publishingVersion, bool isReleaseOnlyPackageVersion, TaskLoggingHelper log) { if (artifacts == null) { throw new ArgumentNullException(nameof(artifacts)); } var blobArtifacts = new List <BlobArtifactModel>(); var packageArtifacts = new List <PackageArtifactModel>(); foreach (var artifact in artifacts) { if (string.Equals(artifact.GetMetadata("ExcludeFromManifest"), "true", StringComparison.OrdinalIgnoreCase)) { continue; } var isSymbolsPackage = artifact.ItemSpec.EndsWith(".symbols.nupkg", StringComparison.OrdinalIgnoreCase) || artifact.ItemSpec.EndsWith(".snupkg", StringComparison.OrdinalIgnoreCase); if (artifact.ItemSpec.EndsWith(".nupkg", StringComparison.OrdinalIgnoreCase) && !isSymbolsPackage) { packageArtifacts.Add(BuildManifestUtil.CreatePackageArtifactModel(artifact)); } else { if (isSymbolsPackage) { string fileName = Path.GetFileName(artifact.ItemSpec); artifact.SetMetadata("RelativeBlobPath", $"{BuildManifestUtil.AssetsVirtualDir}symbols/{fileName}"); } blobArtifacts.Add(BuildManifestUtil.CreateBlobArtifactModel(artifact, log)); } } var signingInfoModel = CreateSigningInformationModelFromItems( itemsToSign, strongNameSignInfo, fileSignInfo, fileExtensionSignInfo, certificatesSignInfo, blobArtifacts, packageArtifacts, log); var buildModel = CreateModel( blobArtifacts, packageArtifacts, buildId, manifestBuildData, repoUri, repoBranch, repoCommit, isStableBuild, publishingVersion, isReleaseOnlyPackageVersion, log, signingInformationModel: signingInfoModel); return(buildModel); }
private async Task <bool> ExecuteAsync() { try { Log.LogMessage(MessageImportance.High, "Performing feed push..."); if (ItemsToPush == null) { Log.LogError($"No items to push. Please check ItemGroup ItemsToPush."); } else if (string.IsNullOrWhiteSpace(ExpectedFeedUrl) || string.IsNullOrWhiteSpace(AccountKey)) { Log.LogError($"{nameof(ExpectedFeedUrl)} / {nameof(AccountKey)} is not set properly."); } else if (string.IsNullOrWhiteSpace(AssetManifestPath)) { Log.LogError($"{nameof(AssetManifestPath)} is not set properly."); } else if (MaxClients <= 0) { Log.LogError($"{nameof(MaxClients)} should be greater than zero."); } else if (UploadTimeoutInMinutes <= 0) { Log.LogError($"{nameof(UploadTimeoutInMinutes)} should be greater than zero."); } if (Log.HasLoggedErrors) { return(false); } BlobFeedAction blobFeedAction = new BlobFeedAction(ExpectedFeedUrl, AccountKey, Log); var pushOptions = new PushOptions { AllowOverwrite = Overwrite, PassIfExistingItemIdentical = PassIfExistingItemIdentical }; IEnumerable <BlobArtifactModel> blobArtifacts = Enumerable.Empty <BlobArtifactModel>(); IEnumerable <PackageArtifactModel> packageArtifacts = Enumerable.Empty <PackageArtifactModel>(); if (!SkipCreateContainer) { await blobFeedAction.CreateContainerAsync(BuildEngine, PublishFlatContainer); } if (PublishFlatContainer) { await blobFeedAction.PublishToFlatContainerAsync(ItemsToPush, MaxClients, pushOptions); blobArtifacts = ConcatBlobArtifacts(blobArtifacts, ItemsToPush); } else { ITaskItem[] symbolItems = ItemsToPush .Where(i => i.ItemSpec.Contains("symbols.nupkg")) .Select(i => { string fileName = Path.GetFileName(i.ItemSpec); i.SetMetadata("RelativeBlobPath", $"{BuildManifestUtil.AssetsVirtualDir}symbols/{fileName}"); return(i); }) .ToArray(); ITaskItem[] packageItems = ItemsToPush .Where(i => !symbolItems.Contains(i)) .ToArray(); var packagePaths = packageItems.Select(i => i.ItemSpec); if (!blobFeedAction.PushToFeedAsync(packagePaths, pushOptions).Result) { return(!Log.HasLoggedErrors); } await blobFeedAction.PublishToFlatContainerAsync(symbolItems, MaxClients, pushOptions); if (Log.HasLoggedErrors) { return(!Log.HasLoggedErrors); } packageArtifacts = ConcatPackageArtifacts(packageArtifacts, packageItems); blobArtifacts = ConcatBlobArtifacts(blobArtifacts, symbolItems); } if (!BuildManifestUtil.ManifestBuildDataHasLocationInformation(ManifestBuildData)) { string[] locationAttribute = new string[] { $"Location={ExpectedFeedUrl}" }; ManifestBuildData = ManifestBuildData == null ? locationAttribute : ManifestBuildData.Concat(locationAttribute).ToArray(); } BuildManifestUtil.CreateBuildManifest(Log, blobArtifacts, packageArtifacts, AssetManifestPath, ManifestRepoUri, ManifestBuildId, ManifestBranch, ManifestCommit, ManifestBuildData, IsStableBuild, PublishingInfraVersion.Legacy, IsReleaseOnlyPackageVersion); } catch (Exception e) { Log.LogErrorFromException(e, true); } return(!Log.HasLoggedErrors); }
public async Task <bool> ExecuteAsync() { try { Log.LogMessage(MessageImportance.High, "Publishing artifacts to feed."); if (string.IsNullOrWhiteSpace(AssetManifestPath) || !File.Exists(AssetManifestPath)) { Log.LogError($"Problem reading asset manifest path from '{AssetManifestPath}'"); } if (!Directory.Exists(BlobAssetsBasePath)) { Log.LogError($"Problem reading blob assets from {BlobAssetsBasePath}"); } if (!Directory.Exists(PackageAssetsBasePath)) { Log.LogError($"Problem reading package assets from {PackageAssetsBasePath}"); } var buildModel = BuildManifestUtil.ManifestFileToModel(AssetManifestPath, Log); // Parsing the manifest may fail for several reasons if (Log.HasLoggedErrors) { return(false); } // Fetch Maestro record of the build. We're going to use it to get the BAR ID // of the assets being published so we can add a new location for them. IMaestroApi client = ApiFactory.GetAuthenticated(MaestroApiEndpoint, BuildAssetRegistryToken); Maestro.Client.Models.Build buildInformation = await client.Builds.GetBuildAsync(BARBuildId); foreach (var fc in TargetFeedConfig) { var feedConfig = new FeedConfig() { TargetFeedURL = fc.GetMetadata("TargetURL"), Type = fc.GetMetadata("Type"), FeedKey = fc.GetMetadata("Token") }; if (string.IsNullOrEmpty(feedConfig.TargetFeedURL) || string.IsNullOrEmpty(feedConfig.Type) || string.IsNullOrEmpty(feedConfig.FeedKey)) { Log.LogError($"Invalid FeedConfig entry. TargetURL='{feedConfig.TargetFeedURL}' Type='{feedConfig.Type}' Token='{feedConfig.FeedKey}'"); } FeedConfigs.Add(fc.ItemSpec.Trim().ToUpper(), feedConfig); } // Return errors from parsing FeedConfig if (Log.HasLoggedErrors) { return(false); } SplitArtifactsInCategories(buildModel); await HandlePackagePublishingAsync(client, buildInformation); await HandleBlobPublishingAsync(client, buildInformation); } catch (Exception e) { Log.LogErrorFromException(e, true); } return(!Log.HasLoggedErrors); }
public override bool Execute() { try { Log.LogMessage(MessageImportance.High, "Performing push to Azure DevOps artifacts storage."); if (!string.IsNullOrWhiteSpace(AssetsTemporaryDirectory)) { Log.LogMessage(MessageImportance.High, $"It's no longer necessary to specify a value for the {nameof(AssetsTemporaryDirectory)} property. " + $"Please consider patching your code to not use it."); } if (ItemsToPush == null) { Log.LogError($"No items to push. Please check ItemGroup ItemsToPush."); } else { IEnumerable <BlobArtifactModel> blobArtifacts = Enumerable.Empty <BlobArtifactModel>(); IEnumerable <PackageArtifactModel> packageArtifacts = Enumerable.Empty <PackageArtifactModel>(); var itemsToPushNoExcludes = ItemsToPush. Where(i => !string.Equals(i.GetMetadata("ExcludeFromManifest"), "true", StringComparison.OrdinalIgnoreCase)); if (PublishFlatContainer) { // Act as if %(PublishFlatContainer) were true for all items. blobArtifacts = itemsToPushNoExcludes .Select(BuildManifestUtil.CreateBlobArtifactModel); foreach (var blobItem in itemsToPushNoExcludes) { if (!File.Exists(blobItem.ItemSpec)) { Log.LogError($"Could not find file {blobItem.ItemSpec}."); continue; } Log.LogMessage(MessageImportance.High, $"##vso[artifact.upload containerfolder=BlobArtifacts;artifactname=BlobArtifacts]{blobItem.ItemSpec}"); } } else { ITaskItem[] symbolItems = itemsToPushNoExcludes .Where(i => i.ItemSpec.Contains("symbols.nupkg")) .Select(i => { string fileName = Path.GetFileName(i.ItemSpec); i.SetMetadata("RelativeBlobPath", $"{BuildManifestUtil.AssetsVirtualDir}symbols/{fileName}"); return(i); }) .ToArray(); var blobItems = itemsToPushNoExcludes .Where(i => { var isFlatString = i.GetMetadata("PublishFlatContainer"); if (!string.IsNullOrEmpty(isFlatString) && bool.TryParse(isFlatString, out var isFlat)) { return(isFlat); } return(false); }) .Union(symbolItems) .ToArray(); ITaskItem[] packageItems = itemsToPushNoExcludes .Except(blobItems) .ToArray(); foreach (var packagePath in packageItems) { if (!File.Exists(packagePath.ItemSpec)) { Log.LogError($"Could not find file {packagePath.ItemSpec}."); continue; } Log.LogMessage(MessageImportance.High, $"##vso[artifact.upload containerfolder=PackageArtifacts;artifactname=PackageArtifacts]{packagePath.ItemSpec}"); } foreach (var blobItem in blobItems) { if (!File.Exists(blobItem.ItemSpec)) { Log.LogError($"Could not find file {blobItem.ItemSpec}."); continue; } Log.LogMessage(MessageImportance.High, $"##vso[artifact.upload containerfolder=BlobArtifacts;artifactname=BlobArtifacts]{blobItem.ItemSpec}"); } packageArtifacts = packageItems.Select(BuildManifestUtil.CreatePackageArtifactModel); blobArtifacts = blobItems.Select(BuildManifestUtil.CreateBlobArtifactModel).Where(blob => blob != null); } PublishingInfraVersion targetPublishingVersion = PublishingInfraVersion.Latest; if (!string.IsNullOrEmpty(PublishingVersion)) { if (!Enum.TryParse(PublishingVersion, ignoreCase: true, out targetPublishingVersion)) { Log.LogError($"Could not parse publishing infra version '{PublishingVersion}'"); } } SigningInformationModel signingInformationModel = BuildManifestUtil.CreateSigningInformationModelFromItems(AzureDevOpsCollectionUri, AzureDevOpsProject, AzureDevOpsBuildId, ItemsToSign, StrongNameSignInfo, FileSignInfo, FileExtensionSignInfo); BuildManifestUtil.CreateBuildManifest(Log, blobArtifacts, packageArtifacts, AssetManifestPath, ManifestRepoUri, ManifestBuildId, ManifestBranch, ManifestCommit, ManifestBuildData, IsStableBuild, targetPublishingVersion, signingInformationModel: signingInformationModel); Log.LogMessage(MessageImportance.High, $"##vso[artifact.upload containerfolder=AssetManifests;artifactname=AssetManifests]{AssetManifestPath}"); } } catch (Exception e) { Log.LogErrorFromException(e, true); } return(!Log.HasLoggedErrors); }
public override bool Execute() { try { Log.LogMessage(MessageImportance.High, "Performing push to Azure DevOps artifacts storage."); if (ItemsToPush == null) { Log.LogError($"No items to push. Please check ItemGroup ItemsToPush."); } else { IEnumerable <BlobArtifactModel> blobArtifacts = Enumerable.Empty <BlobArtifactModel>(); IEnumerable <PackageArtifactModel> packageArtifacts = Enumerable.Empty <PackageArtifactModel>(); if (PublishFlatContainer) { blobArtifacts = ItemsToPush.Select(BuildManifestUtil.CreateBlobArtifactModel).Where(blob => blob != null); } else { ITaskItem[] symbolItems = ItemsToPush .Where(i => i.ItemSpec.Contains("symbols.nupkg")) .Select(i => { string fileName = Path.GetFileName(i.ItemSpec); i.SetMetadata("RelativeBlobPath", $"{BuildManifestUtil.AssetsVirtualDir}symbols/{fileName}"); return(i); }) .ToArray(); ITaskItem[] packageItems = ItemsToPush .Where(i => !symbolItems.Contains(i)) .ToArray(); foreach (var packagePath in packageItems) { Log.LogMessage(MessageImportance.High, $"##vso[artifact.upload containerfolder=PackageArtifacts;artifactname=PackageArtifacts]{packagePath.ItemSpec}"); } foreach (var symbolPath in symbolItems) { Log.LogMessage(MessageImportance.High, $"##vso[artifact.upload containerfolder=BlobArtifacts;artifactname=BlobArtifacts]{symbolPath.ItemSpec}"); } packageArtifacts = packageItems.Select(BuildManifestUtil.CreatePackageArtifactModel); blobArtifacts = symbolItems.Select(BuildManifestUtil.CreateBlobArtifactModel).Where(blob => blob != null); } BuildManifestUtil.CreateBuildManifest(Log, blobArtifacts, packageArtifacts, AssetManifestPath, ManifestRepoUri, ManifestBuildId, ManifestBranch, ManifestCommit, ManifestBuildData); } } catch (Exception e) { Log.LogErrorFromException(e, true); } return(!Log.HasLoggedErrors); }
public async Task <bool> ExecuteAsync() { try { Log.LogMessage(MessageImportance.High, "Performing feed push..."); if (ItemsToPush == null) { Log.LogError($"No items to push. Please check ItemGroup ItemsToPush."); } else { BlobFeedAction blobFeedAction = new BlobFeedAction(ExpectedFeedUrl, AccountKey, Log); IEnumerable <BlobArtifactModel> blobArtifacts = Enumerable.Empty <BlobArtifactModel>(); IEnumerable <PackageArtifactModel> packageArtifacts = Enumerable.Empty <PackageArtifactModel>(); if (!SkipCreateContainer) { await blobFeedAction.CreateContainerAsync(BuildEngine, PublishFlatContainer); } if (PublishFlatContainer) { await PublishToFlatContainerAsync(ItemsToPush, blobFeedAction); blobArtifacts = ConcatBlobArtifacts(blobArtifacts, ItemsToPush); } else { ITaskItem[] symbolItems = ItemsToPush .Where(i => i.ItemSpec.Contains("symbols.nupkg")) .Select(i => { string fileName = Path.GetFileName(i.ItemSpec); i.SetMetadata("RelativeBlobPath", $"{BuildManifestUtil.AssetsVirtualDir}symbols/{fileName}"); return(i); }) .ToArray(); ITaskItem[] packageItems = ItemsToPush .Where(i => !symbolItems.Contains(i)) .ToArray(); var packagePaths = packageItems.Select(i => i.ItemSpec); await blobFeedAction.PushToFeedAsync(packagePaths, CreatePushOptions()); await PublishToFlatContainerAsync(symbolItems, blobFeedAction); packageArtifacts = ConcatPackageArtifacts(packageArtifacts, packageItems); blobArtifacts = ConcatBlobArtifacts(blobArtifacts, symbolItems); } BuildManifestUtil.CreateBuildManifest(Log, blobArtifacts, packageArtifacts, AssetManifestPath, ManifestRepoUri, ManifestBuildId, ManifestBranch, ManifestCommit, ManifestBuildData); } } catch (Exception e) { Log.LogErrorFromException(e, true); } return(!Log.HasLoggedErrors); }
public async Task <bool> ExecuteAsync() { try { Log.LogMessage(MessageImportance.High, "Performing push feeds."); if (string.IsNullOrWhiteSpace(ExpectedFeedUrl) || string.IsNullOrWhiteSpace(AccountKey)) { Log.LogError($"{nameof(ExpectedFeedUrl)} / {nameof(AccountKey)} is not set properly."); } else if (string.IsNullOrWhiteSpace(AssetManifestPath) || !File.Exists(AssetManifestPath)) { Log.LogError($"Problem reading asset manifest path from {AssetManifestPath}"); } else if (MaxClients <= 0) { Log.LogError($"{nameof(MaxClients)} should be greater than zero."); } else if (UploadTimeoutInMinutes <= 0) { Log.LogError($"{nameof(UploadTimeoutInMinutes)} should be greater than zero."); } var buildModel = BuildManifestUtil.ManifestFileToModel(AssetManifestPath, Log); // Parsing the manifest may fail for several reasons if (Log.HasLoggedErrors) { return(false); } var blobFeedAction = new BlobFeedAction(ExpectedFeedUrl, AccountKey, Log); var pushOptions = new PushOptions { AllowOverwrite = Overwrite, PassIfExistingItemIdentical = PassIfExistingItemIdentical }; if (buildModel.Artifacts.Packages.Any()) { if (!Directory.Exists(PackageAssetsBasePath)) { Log.LogError($"Invalid {nameof(PackageAssetsBasePath)} was supplied: {PackageAssetsBasePath}"); return(false); } PackageAssetsBasePath = PackageAssetsBasePath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar) + Path.DirectorySeparatorChar; var packages = buildModel.Artifacts.Packages.Select(p => $"{PackageAssetsBasePath}{p.Id}.{p.Version}.nupkg"); await blobFeedAction.PushToFeedAsync(packages, pushOptions); } if (buildModel.Artifacts.Blobs.Any()) { if (!Directory.Exists(BlobAssetsBasePath)) { Log.LogError($"Invalid {nameof(BlobAssetsBasePath)} was supplied: {BlobAssetsBasePath}"); return(false); } BlobAssetsBasePath = BlobAssetsBasePath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar) + Path.DirectorySeparatorChar; var blobs = buildModel.Artifacts.Blobs .Select(blob => { var fileName = Path.GetFileName(blob.Id); return(new MSBuild.TaskItem($"{BlobAssetsBasePath}{fileName}", new Dictionary <string, string> { { "RelativeBlobPath", $"{BuildManifestUtil.AssetsVirtualDir}{blob.Id}" } })); }) .ToArray(); await blobFeedAction.PublishToFlatContainerAsync(blobs, MaxClients, UploadTimeoutInMinutes, pushOptions); } } catch (Exception e) { Log.LogErrorFromException(e, true); } return(!Log.HasLoggedErrors); }