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); }
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 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 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 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); }