how do I use "nuget push" with the --skip-duplicate option in task DotNetCoreCLI@2

Viewed 7234

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)

3 Answers

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'

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 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'
Related