Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore duplicates when pushing nuget package to nuget.org from VSTS

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)?

like image 244
jgauffin Avatar asked Sep 08 '17 11:09

jgauffin


People also ask

What is Apikey NuGet?

The API key acts as an alias for the user account, so the same API key is used for all NuGet repositories within the repository manager.

How do I push a package to MyGet?

You can configure your Azure DevOps Pipeline to publish packages to MyGet by adding NuGet build tasks to the pipeline configuration with the Azure DevOps UI or by adding a YAML file with the correct parameters to the root of your project's source code repo.

How do I trust a NuGet package?

Look at package author in Visual Studio. Refer to nuget.org to look at package owners and number of downloads (and sometimes source code) If the package owners somewhat match the author in Visual Studio, and the package seems generally trusted in the community, then add the package reference.

How do you set the local path of NuGet EXE to your path environment variable?

Click “Advanced System Settings” then click the “Environment Variables” button located within the Advanced tab. From here double-click the PATH variable in the top panel and create a new entry by adding the path to the directory that contains your NuGet.exe file (in this instance it's C:/NuGet/).


2 Answers

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

like image 106
Dariusz Woźniak Avatar answered Sep 27 '22 21:09

Dariusz Woźniak


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.

like image 38
starian chen-MSFT Avatar answered Sep 27 '22 22:09

starian chen-MSFT