Reputation: 39474
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?
Upvotes: 9
Views: 10895
Reputation: 1111
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
Upvotes: 3
Reputation: 15654
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.
Upvotes: 0
Reputation: 1481
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
Upvotes: -5