5

In Azure DevOps Server (version 2019.0.1) running on a Windows Server 2019 agent, with the 'Allow duplicates to be skipped' option selected for NuGet push task, a warning is displayed:

The 'Allow duplicates to be skipped' option is currently only available on Azure Pipelines. If NuGet.exe encounters a conflict, the task will fail.

The task results in the following error that causes the task to fail indicating that the above warning applies:

Response status code does not indicate success: 409 (Conflict - The feed already contains 'MyPackage X.Y.Z'. (DevOps Activity ID: 1A57312F-3C56-4E4D-9E78-73C7072A288F)).

I'm wondering if this issue is particular to Azure DevOps Server (rather than Azure DevOps Services), or if I'm doing something wrong, or if there is another workaround. I noticed someone else has the same issue from this comment on another question where it was mentioned that the option was available after someone asked how to ignore error 409 (duplicate package).

I would like to ignore duplicate packages using the NuGet task and ideally the 'Allow duplicates to be skipped' option on Azure DevOps Server. I'm aware that it could be resolved using scripting, but I'd prefer to avoid that if possible. Any help appreciated.

Neo
  • 4,145
  • 6
  • 53
  • 76
  • You can try it on tfs2018. If there is no problem, it may be that this function is not available on tfs2019.01.You can also check whether the same problem exists if you push other packages. – Hugh Lin Jul 05 '19 at 10:08

3 Answers3

5

If you're using the NuGetCommand@2 Azure Pipelines task, you can use the allowPackageConflicts parameter.

allowPackageConflicts

It allows the task to report success even if some of your packages are rejected with 409 Conflict errors. This option is currently only available on Azure Pipelines and using Windows agents. If NuGet.exe encounters a conflict, the task will fail. This option will not work and publish will fail if you are within a proxy environment.

https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/package/nuget

Tom Pažourek
  • 9,582
  • 8
  • 66
  • 107
  • 1
    this parameter on this task doesn't seem to work when pushing to nuget.org even if it returns a 409 – Jeff Oct 13 '20 at 21:59
  • 2
    @Jeff, I thought I had the same problem, but for me it turned out I was not using `NuGetCommand@2` but `DotNetCoreCli@2`, which seems similar but doesn't have the same options: `allowPackageConflicts` is not supported. Maybe this helps? – Erijk Nov 12 '20 at 10:00
4

I don't know about the Azure DevOps task, but if you upgrade to nuget.exe 5.1, you can use the new -SkipDuplicate option. This should work for any NuGet server that correctly implements the NuGet protocol and on any CI server/agent.

zivkan
  • 12,793
  • 2
  • 34
  • 51
  • 2
    I'm using the NuGet Tool Installer task to specify 5.1.0, but this question is about getting it working using the Azure DevOps NuGet task. As I mentioned, I'm aware it can be resolving using scripting (where I would call nuget.exe directly), but I want to avoid that. This is more about insight into Azure DevOps pipeline tasks. – Neo Jul 02 '19 at 15:50
3

If you switch to azure pipelines (it seems it's the new way of doing things) you can use dotnet commands. the option --skip-duplicate will be available in dotnet core 3.1 (still in preview) for the dotnet nuget push command (no need to use NuGet command as it's already available in dotnet). But you can use it now if you install the latest .NET Core.

For example, this is a stage that will grab whichever nuGet you've got in a specific folder, install the latest dotnet core that supports the skip duplicates and push it to the repository feed.

- stage:
  displayName: 'Release'
  condition: succeeded()
  jobs:
    - job: 'Publish'
      displayName: 'Publish nuGet Package'
      steps:
        - download: current
          artifact: $(PIPELINE_ARTIFACT_NAME)
          displayName: 'Download pipeline artifact'
        - script: ls $(PATH_PIPELINE_ARTIFACT_NAME)
          displayName: 'Display contents of downloaded articacts path'
        - task: NuGetAuthenticate@0
          displayName: 'Authenticate in NuGet feed'
        - task: UseDotNet@2
          displayName: 'Use .NET Core sdk 3.1 (preview)'
          inputs:
            packageType: sdk
            version: '3.1.100-preview2-014569'
            installationPath: $(Agent.ToolsDirectory)/dotnet
        - script: dotnet nuget push $(PATH_PIPELINE_ARTIFACT_NAME)/**/*.nupkg --source $(NUGET_FEED) --api-key $(NUGET_API_KEY) --skip-duplicate
          displayName: 'Uploads nuGet packages'
diegosasw
  • 13,734
  • 16
  • 95
  • 159