diff --git a/build/_k-standard-goals.shade b/build/_k-standard-goals.shade index 758544e08d..c6fbe1986f 100644 --- a/build/_k-standard-goals.shade +++ b/build/_k-standard-goals.shade @@ -106,6 +106,7 @@ default Configuration='${E("Configuration")}' #nuget-install target='install' description='Install NuGet packages to local repo' kpm-publish sourcePackagesDir='${BUILD_DIR}' targetPackagesDir='${E("PACKAGES_PUBLISH_DIR")}' + nuget-resilient-publish sourcePackagesDir='${BUILD_DIR}' nugetFeed='${E("NUGET_PUBLISH_FEED")}' if='!string.IsNullOrEmpty(E("NUGET_PUBLISH_FEED"))' #xunit-test target='test' if='Directory.Exists("test")' k-test each='var projectFile in Files.Include("test/**/project.json")' diff --git a/build/_nuget-resilient-publish.shade b/build/_nuget-resilient-publish.shade new file mode 100644 index 0000000000..cc4a2b96ba --- /dev/null +++ b/build/_nuget-resilient-publish.shade @@ -0,0 +1,42 @@ +use namespace="System.Threading.Tasks" + +@{/* + +nuget-resilient-publish + Publishes NuGet packages with retries + +sourcePackagesDir='' + Required. Path to packages to push + +nugetFeed='' + Required. Feed to publish to. +*/} + +@{ + var packages = Directory.EnumerateFiles(sourcePackagesDir, "*.nupkg") + .Where(p => !p.EndsWith(".symbols.nupkg")) + .ToArray(); + + Parallel.ForEach(packages, package => + { + var retries = 0; + var packagePath = Path.Combine(sourcePackagesDir, package); + start: + try + { + NuGetPush (nugetFeed, packagePath, ""); + } + catch + { + if (++retries == 3) + { + throw; + } + + goto start; + } + }); +} + +macro name='NuGetPush' source='string' nupkgFile='string' extra='string' + nuget-push