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

4

19

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)

Adorn answered 10/6, 2020 at 14:12 Comment(0)
N
8

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
Noman answered 2/7, 2020 at 15:42 Comment(2)
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.Adorn
afaik nuget authenticate is deprecated in the meantime. did you get it working now? are you using .yaml config or classic config?Mirage
H
7

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'
Handicapper answered 19/7, 2020 at 9:33 Comment(1)
A more nasty way to fix duplicate NuGet, in Azure Devops, is by adding allowPackageConflicts: true Gianna
P
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'
Party answered 11/6, 2020 at 7:34 Comment(5)
This fails with 401 on the internal feedAdorn
This is another question, as this documentation 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: #48068829Party
this works. I think this should be marked as answer.Mirage
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..Mirage
Don't you need --api-key:az ?Weyermann
W
0

I only got it to work using this combination of commands. (It's a variation on the answer @user1624411 gave)

    - task: NuGetAuthenticate@0

    - task: DotNetCoreCLI@2
      displayName: 'dotnet push'
      inputs:
        command: custom
        custom: nuget
        arguments: 'push --source "https://pkgs.dev.azure.com/«organization»/_packaging/«feed»/nuget/v3/index.json" --api-key az --skip-duplicate $(Build.ArtifactStagingDirectory)/**/*.nupkg'
Weyermann answered 7/8 at 15:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.