Search code examples
c#nugetazure-devopscontinuous-deployment

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


Solution

  • 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.