diff --git a/build.fsx b/build.fsx index b580514353c..0d43896b7c8 100644 --- a/build.fsx +++ b/build.fsx @@ -836,14 +836,18 @@ Target.Create "DotnetCoreCreateDebianPackage" (fun _ -> let nuget_exe = Directory.GetCurrentDirectory() "packages" "build" "NuGet.CommandLine" "tools" "NuGet.exe" let apikey = Environment.environVarOrDefault "nugetkey" "" let nugetsource = Environment.environVarOrDefault "nugetsource" "https://www.nuget.org/api/v2/package" -let nugetPush nugetpackage = - if not <| System.String.IsNullOrEmpty apikey then - Process.ExecProcess (fun info -> - info.FileName <- nuget_exe - info.Arguments <- sprintf "push %s %s -Source %s" (Process.toParam nugetpackage) (Process.toParam apikey) (Process.toParam nugetsource)) - (System.TimeSpan.FromMinutes 10.) - |> (fun r -> if r <> 0 then failwithf "failed to push package %s" nugetpackage) - else Trace.traceFAKE "could not push '%s', because api key was not set" nugetpackage +let rec nugetPush tries nugetpackage = + try + if not <| System.String.IsNullOrEmpty apikey then + Process.ExecProcess (fun info -> + info.FileName <- nuget_exe + info.Arguments <- sprintf "push %s %s -Source %s" (Process.toParam nugetpackage) (Process.toParam apikey) (Process.toParam nugetsource)) + (System.TimeSpan.FromMinutes 10.) + |> (fun r -> if r <> 0 then failwithf "failed to push package %s" nugetpackage) + else Trace.traceFAKE "could not push '%s', because api key was not set" nugetpackage + with exn when tries > 1 -> + Trace.traceFAKE "Error while pushing NuGet package: %s" exn.Message + nugetPush (tries - 1) nugetpackage Target.Create "DotnetCorePushNuGet" (fun _ -> // dotnet pack @@ -853,7 +857,7 @@ Target.Create "DotnetCorePushNuGet" (fun _ -> let projName = Path.GetFileName(Path.GetDirectoryName proj) !! (sprintf "nuget/dotnetcore/%s.*.nupkg" projName) -- (sprintf "nuget/dotnetcore/%s.*.symbols.nupkg" projName) - |> Seq.iter nugetPush) + |> Seq.iter (nugetPush 4)) ) Target.Create "PublishNuget" (fun _ -> diff --git a/src/app/Fake.DotNet.NuGet/NuGet.fs b/src/app/Fake.DotNet.NuGet/NuGet.fs index 7dcd9906516..97a04cc084e 100644 --- a/src/app/Fake.DotNet.NuGet/NuGet.fs +++ b/src/app/Fake.DotNet.NuGet/NuGet.fs @@ -335,9 +335,8 @@ let rec private publish parameters = info.Arguments <- args) parameters.TimeOut finally setEnableProcessTracing tracing if result <> 0 then failwithf "Error during NuGet push. %s %s" parameters.ToolPath args - with exn -> - if parameters.PublishTrials > 0 then publish { parameters with PublishTrials = parameters.PublishTrials - 1 } - else raise exn + with exn when parameters.PublishTrials > 0 -> + publish { parameters with PublishTrials = parameters.PublishTrials - 1 } /// push package to symbol server (and try again if something fails) let rec private publishSymbols parameters = @@ -358,9 +357,8 @@ let rec private publishSymbols parameters = info.Arguments <- args) parameters.TimeOut finally setEnableProcessTracing tracing if result <> 0 then failwithf "Error during NuGet symbol push. %s %s" parameters.ToolPath args - with exn -> - if parameters.PublishTrials > 0 then publish { parameters with PublishTrials = parameters.PublishTrials - 1 } - else raise exn + with exn when parameters.PublishTrials > 0-> + publish { parameters with PublishTrials = parameters.PublishTrials - 1 } /// Creates a new NuGet package based on the given .nuspec or project file. /// The .nuspec / projectfile is passed as-is (no templating is performed)