Пример #1
0
        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);

                    if (!SkipCreateContainer)
                    {
                        await blobFeedAction.CreateContainerAsync(this.BuildEngine);
                    }

                    List <string> items = ConvertToStringLists(ItemsToPush);

                    if (!PublishFlatContainer)
                    {
                        await blobFeedAction.PushToFeed(items, Overwrite);
                    }
                    else
                    {
                        using (var clientThrottle = new SemaphoreSlim(this.MaxClients, this.MaxClients))
                        {
                            Log.LogMessage($"Uploading {ItemsToPush.Length} items...");
                            await Task.WhenAll(ItemsToPush.Select(item => blobFeedAction.UploadAssets(item, clientThrottle, Overwrite)));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log.LogErrorFromException(e, true);
            }

            return(!Log.HasLoggedErrors);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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
                    {
                        var symbolItems = ItemsToPush.Where(i => i.ItemSpec.Contains("symbols.nupkg")).Select(i =>
                        {
                            string fileName = Path.GetFileName(i.ItemSpec);
                            i.SetMetadata("RelativeBlobPath", $"symbols/{fileName}");
                            return(i);
                        }).ToArray();

                        ITaskItem[] packageItems = ItemsToPush
                                                   .Where(i => !symbolItems.Contains(i))
                                                   .ToArray();

                        var packagePaths = packageItems.Select(i => i.ItemSpec);

                        await blobFeedAction.PushToFeed(packagePaths, Overwrite);
                        await PublishToFlatContainerAsync(symbolItems, blobFeedAction);

                        packageArtifacts = ConcatPackageArtifacts(packageArtifacts, packageItems);
                        blobArtifacts    = ConcatBlobArtifacts(blobArtifacts, symbolItems);
                    }

                    if (!SkipCreateManifest)
                    {
                        await PushBuildManifestAsync(blobFeedAction, blobArtifacts, packageArtifacts);
                    }
                }
            }
            catch (Exception e)
            {
                Log.LogErrorFromException(e, true);
            }

            return(!Log.HasLoggedErrors);
        }