7
votes

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 as follows:

https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops

I gave full access to the user when generated the token.

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?

3
why dont you use the built-in task?4c74356b41
Have you tried to get the PAT token from Azure Devops portal?Tom Sun - MSFT
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-MSFT
@TomSun Yes, that is how I got the token ...Miguel Moura
@4c74356b41 What do you mean? Can you explain?Miguel Moura

3 Answers

0
votes

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://docs.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.

0
votes

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://docs.microsoft.com/en-us/azure/devops/artifacts/nuget/publish?view=azure-devops#create-and-publish-your-own-nuget-package

-4
votes

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://docs.microsoft.com/en-us/azure/devops/artifacts/get-started-nuget?view=azure-devops&tabs=new-nav