Skip to content

Commit

Permalink
add NuGet push retries, fixes #1683
Browse files Browse the repository at this point in the history
  • Loading branch information
matthid committed Sep 25, 2017
1 parent c1a471c commit 622bd0e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
22 changes: 13 additions & 9 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 _ ->
Expand Down
10 changes: 4 additions & 6 deletions src/app/Fake.DotNet.NuGet/NuGet.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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)
Expand Down

0 comments on commit 622bd0e

Please sign in to comment.