16

In Azure DevOps, I'd like to use the dotnet core CLI task to push a package with the --skip-duplicate option set. How do I do that?

I tried to set arguments: --skip-duplicate, but that's not getting reflected in the executed command.

I tried custom command with custom: nuget push, but that indicates nuget push isn't a valid custom command.

How do I make the DotNetCorCLI@2 task perform dotnet nuget push <pathspec> --skip-duplicate (with also the --source option set to an internal package source)

huysmania
  • 1,054
  • 5
  • 11
Martijn
  • 11,964
  • 12
  • 50
  • 96

3 Answers3

6

You should be able to use the nuget authenticate and the nuget push instead of the dotnet core CLI. It has a couple of more features

- task: NuGetAuthenticate@0
  displayName: 'NuGet Authenticate'
- task: NuGetCommand@2
  displayName: 'NuGet push'
  inputs:
    packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg'
    command: push
    feedsToUse: 'select'
    publishVstsFeed: 'feedname'
    allowPackageConflicts: true
  • I've been going back and forth between the different ways to do things. I can' remember offhand why the NugetCommand wasn't able to do what I wanted. I'll give it another go. – Martijn Jul 03 '20 at 11:25
  • afaik nuget authenticate is deprecated in the meantime. did you get it working now? are you using .yaml config or classic config? – yBother Nov 24 '21 at 16:59
  • worked for me thanks! – n.podbielski Aug 10 '23 at 09:03
5

Try to use custom: nuget and put the push in argument. Check the following syntax:

steps:
- task: DotNetCoreCLI@2
  displayName: 'dotnet nuget push'
  inputs:
    command: custom
    custom: nuget
    arguments: 'push *.nupkg -s https://pkgs.dev.azure.com/xxxx/_packaging/xxx/nuget/v3/index.json --skip-duplicate'
Cece Dong - MSFT
  • 29,631
  • 1
  • 24
  • 39
  • 1
    This fails with 401 on the internal feed – Martijn Jun 11 '20 at 12:51
  • 1
    This is another question, as [this documentation](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-nuget-push) indicates: The `dotnet nuget push` command pushes a package to the server and publishes it. The push command uses server and credential details found in the system's NuGet config file or chain of config files. So, the NuGet package credential and API key should be added in the NuGet.config file. Check the answer this this case: https://stackoverflow.com/questions/48068329/push-a-nuget-package-to-vsts-with-net-cli – Cece Dong - MSFT Jun 12 '20 at 02:46
  • this works. I think this should be marked as answer. – yBother Nov 18 '21 at 15:49
  • 1
    i am wondering if there is a more straight forward approach to make use of skip-duplicates in build pipeline. I do not want to workaround 401 error.. to be honest I am kind of disappointed that this procedure obviously is not very mature.. – yBother Nov 25 '21 at 17:26
5

I had the same issue. I managed to fix it this way:

- task: NuGetAuthenticate@0
- script: dotnet nuget push --api-key az --skip-duplicate --source https://pkgs.dev.azure.com/{organization}/{project?}/_packaging/{feed1}/nuget/v3/index.json *.nupkg
  workingDirectory: $(Build.ArtifactStagingDirectory)

Of course, replace {organization} with your org name in azure.

{project?} is useless if your feed is organization scoped and {feed1} is your nuget feed name.

The NuGetAuthenticate task will authenticate by default all feeds within azure. To get authentication works outside azure feeds, take a look to the official docs

Update

If nuget push randomly fails with 401, an accepted workaround is to add these variables to your yaml, as suggested here

variables:
  NUGET_PLUGIN_REQUEST_TIMEOUT_IN_SECONDS: '30'
  NUGET_PLUGIN_HANDSHAKE_TIMEOUT_IN_SECONDS: '30'
user1624411
  • 398
  • 4
  • 6
  • A more nasty way to fix duplicate NuGet, in Azure Devops, is by adding ```allowPackageConflicts: true ``` – Henkie85 Feb 24 '21 at 12:57