Ignore duplicates when pushing nuget package to nu

2020-04-08 10:57发布

I got a build in VSTS that are triggered on every commit in the repository. Everything works great with one exception.

We do not release a new version of the nuget package on every commit. So our nuget push build step fails with http status code 409. I've configured that step so that it can continue anyway.

Due to the error the build is just "partially successful". I'm using the a build badge which also states the same (without context).

How can I tell VSTS to ignore 409 or just replace the existing package (on nuget.org)?

2条回答
祖国的老花朵
2楼-- · 2020-04-08 11:27

Use -skipDuplicate flag (available since NuGet 5.1):

(5.1+) If a package and version already exists, skip it and continue with the next package in the push, if any.

Source: https://docs.microsoft.com/en-us/nuget/reference/cli-reference/cli-ref-push#options

查看更多
▲ chillily
3楼-- · 2020-04-08 11:45

You can’t ignore 409 error in VSTS build and can’t replace the existing package in server.

I recommend that you can push the package in the release and fail the release if package is existing.

Another way is that, you can check the package in server before push package (e.g. PowerShell, REST API) during the build and set the condition for push package task (Custom Condition).

For example:

  1. Add a variable to build definition (e.g. hasPackage true)
  2. Check packages (PowerShell, Rest API etc…)
  3. If the package is existing, set the variable to false ("##vso[task.setvariable variable=hasPackage;]false")
  4. Set Custom condition for push package task (e.g. eq(variables['hasPackage'],'false'))

Update:

Allow duplicates to be skipped is supported in NuGet Push Task now! (Just check Allow duplicates to be skipped option in NuGet Push task.

查看更多
登录 后发表回答