8

I am trying to push a Nuget package to Azure DevOps from a MAC.

I created an Azure DevOps artefacts feed and tried to push a package using:

dotnet nuget push 
  --source "https://pkgs.dev.azure.com/MyProject/_packaging/MyFeed/nuget/v2" 
  --api-key "MyToken" 
  "MyPackage.nupkg"

I generated the token by following these instructions: https://learn.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops , granting full access.

I keep having the error:

error: Unable to load the service index for source https://pkgs.dev.azure.com/mdmoura/_packaging/Moleky/nuget/v3/index.json.
error: Response status code does not indicate success: 401 (Unauthorized).

I tried different options but I always get this error ...

What I might be missing?

Vince Bowdren
  • 8,326
  • 3
  • 31
  • 56
Miguel Moura
  • 36,732
  • 85
  • 259
  • 481
  • 2
    why dont you use the built-in task? – 4c74356b41 Feb 11 '19 at 06:22
  • Have you tried to get the [PAT token](https://learn.microsoft.com/en-us/azure/devops/integrate/get-started/authentication/pats?view=azure-devops) from Azure Devops portal? – Tom Sun - MSFT Feb 11 '19 at 08:23
  • Is there a proxy on your computer? If yes, try to remove it and test again. And can you open the source path in the browser directly? – Leo Liu Feb 11 '19 at 08:41
  • 1
    @TomSun Yes, that is how I got the token ... – Miguel Moura Feb 11 '19 at 11:06
  • @4c74356b41 What do you mean? Can you explain? – Miguel Moura Feb 11 '19 at 11:06
  • @LeoLiu-MSFT No, there is no Proxy. Yes, I can open both V3 and V2 on the browser with not problem. But when I push the package I keep getting the unauthorised error. – Miguel Moura Feb 11 '19 at 11:31
  • I have the same issue, it happens because it requires a first login with the Microsoft credentials, it shows a pop up windows to do it, the problem is that I want to add that in the release pipeline and I got stuck with the 401 error. – Fabito Mar 15 '19 at 17:19
  • Does this answer your question? [Push a NuGet package to VSTS with .NET CLI](https://stackoverflow.com/questions/48068329/push-a-nuget-package-to-vsts-with-net-cli) – Vince Bowdren Dec 29 '21 at 23:32

3 Answers3

2

EDIT: As said in comments, the following commads require .NET Core 3.1

Could you try doing this :

dotnet nuget add source "https://pkgs.dev.azure.com/MyProject/_packaging/MyFeed/nuget/v2" --name MyFeed --username "YourUserName" --password "YourPatToken"

And then

dotnet nuget push "MyPackage.nupkg" --source MyFeed --api-key az

That's the equivalence of the nuget way described here : https://learn.microsoft.com/en-us/azure/devops/artifacts/nuget/publish?view=azure-devops#create-and-publish-your-own-nuget-package

Cem.S
  • 1,001
  • 10
  • 15
0

The pipeline is not authenticated in the feed. You need to add an authentication task before you attempt to push nuget packages. Try the following

- task: NuGetAuthenticate@0
  displayName: 'Authenticate in NuGet feed'
- script: dotnet nuget push $(PATH_PIPELINE_ARTIFACT_NAME)/**/*.nupkg --source MyProject --api-key MyToken
  displayName: 'Uploads nuGet packages'

Notice the NuGetAuthenticate@0 task to authenticate beforehand. Nothing else is required to authenticate because it seems you're using Azure DevOps artifacts. Otherwise you would have to create a connection (more info https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/package/nuget-authenticate?view=azure-devops)

As per the command dotnet nuget push notice I wrote a full path with a regular expression **/*.nupkg. Use or replace this PATH_PIPELINE_ARTIFACT_NAME variable with the path where your nuGet packages to be uplodaded are currently located. The regular expression will allow you to publish ALL the nuGet packages in that folder.

diegosasw
  • 13,734
  • 16
  • 95
  • 159
-5

Why are you running dotnet nuget push instead of nuget push?

Do note: the API_KEY here can be any non-empty value, according to the docs: https://learn.microsoft.com/en-us/azure/devops/artifacts/get-started-nuget?view=azure-devops&tabs=new-nav

Rob Bos
  • 1,320
  • 1
  • 10
  • 25
  • 1
    I am using dotnet push because I am running on MAC and nuget is only for windows. Isn't dotnet nuget just nuget? – Miguel Moura Feb 13 '19 at 17:05
  • What Rob was trying to say is that the token is ignored when you use nuget command line (https://learn.microsoft.com/en-us/azure/devops/artifacts/nuget/publish?view=azure-devops#create-and-publish-your-own-nuget-package). I know for a fact that it is true and that a push with a dummy api key works with nuget. Haven't tried with dotnet though. Anyways, here your problem is related to PAT, not the API key ^^ – Cem.S Oct 10 '20 at 15:56
  • By comparing both methods, you should first do a nuget add source (https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-nuget-add-source) and use your token (PAT) as the password. Then only, you can push the package with a dummy api key – Cem.S Oct 10 '20 at 16:03