I'm trying to create a Release Pipeline in Azure DevOps that will publish a package to Nuget.org. The build pipeline works just fine and creates the package as the build artifact. I can publish to a feed hosted in Azure Artifacts, I just cannot publish to Nuget.org. I believe the issue is with the Service Connection. .
I've tried using the ApiKey but that throws an error
DotNet Core does not support encrypted API Key' error
Here is the release step that is attempting to push the package.
I've also tried https://api.nuget.org/v3/index.json for the Feed URL but that doesn't seem to make a difference.
Log output.
2018-10-21T23:27:36.3177322Z ##[section]Starting: Nuget Push 2018-10-21T23:27:36.3183449Z ============================================================================== 2018-10-21T23:27:36.3183547Z Task : .NET Core 2018-10-21T23:27:36.3183635Z Description : Build, test, package, or publish a dotnet application, or run a custom dotnet command. For package commands, supports NuGet.org and authenticated feeds like Package Management and MyGet. 2018-10-21T23:27:36.3183729Z Version : 2.141.0 2018-10-21T23:27:36.3183791Z Author : Microsoft Corporation 2018-10-21T23:27:36.3183871Z Help : More Information 2018-10-21T23:27:36.3183936Z ============================================================================== 2018-10-21T23:27:37.1663123Z [command]C:\Windows\system32\chcp.com 65001 2018-10-21T23:27:37.1762529Z Active code page: 65001 2018-10-21T23:27:37.1808736Z SYSTEMVSSCONNECTION exists true 2018-10-21T23:27:37.3473599Z SYSTEMVSSCONNECTION exists true 2018-10-21T23:27:37.4707171Z SYSTEMVSSCONNECTION exists true 2018-10-21T23:27:37.4739974Z e3e8a3af-5c6c-44e9-820c-c62af0972256 exists true 2018-10-21T23:27:37.4807474Z Saving NuGet.config to a temporary config file. 2018-10-21T23:27:37.4833034Z Saving NuGet.config to a temporary config file. 2018-10-21T23:27:37.4919745Z Using authentication information for the following URI: https://www.nuget.org/api/v2/package 2018-10-21T23:27:37.4988034Z [command]C:\hostedtoolcache\windows\dncs\2.1.105\x64\dotnet.exe nuget push "{package}" --source https://www.nuget.org/api/v2/package --api-key RequiredApiKey 2018-10-21T23:27:38.3984300Z info : Pushing TranslatorConsole.1.0.0.6.nupkg to 'https://www.nuget.org/api/v2/package'... 2018-10-21T23:27:38.4171650Z info : PUT https://www.nuget.org/api/v2/package/ 2018-10-21T23:27:38.8798808Z info : Forbidden https://www.nuget.org/api/v2/package/ 462ms 2018-10-21T23:27:38.9562536Z error: Response status code does not indicate success: 403 (The specified API key is invalid, has expired, or does not have permission to access the specified package.). 2018-10-21T23:27:40.2195255Z ##[error]Error: C:\hostedtoolcache\windows\dncs\2.1.105\x64\dotnet.exe failed with return code: 1 2018-10-21T23:27:40.2206711Z ##[error]Packages failed to publish 2018-10-21T23:27:40.2307763Z ##[section]Finishing: Nuget Push
Enter your Azure DevOps Services feed locator. Example: azure-feed://myOrg/myProject/myFeed@local. Select the Package type(s) you want to use and enter an Upstream source name. Select Save when you are done.
There is an issue tracked in Github: DotNetCore currently does not support using an encrypted Api Key
Using an ApiKey is currently not supported in dotnet because the required libraries for encrypting the key are not available, sorry for the inconvenience. You should be able to use a service endpoint configured with a username/password combination. If you can only use an ApiKey, I would suggest using the nuget 2.* task to push.
So, you can try using the Nuget 2.*
task to push the packages. (Add task --> Package --> Nuget)
Alternately you can try pushing package to NuGet server through Command Line task by calling dotnet nuget push
command to deal with this issue. Reference this thread: error while trying to push nuget package from VSTS
I was dealing with the same problem - publish a nuget to the NuGet.org feed from Azure DevOps. Despite the fact that this answer is still valid, there is an easy way how to do it and the answer didn't help me much.
Generate ApiKey in NuGet.org administration.
Add ApiKey as a secret variable to your pipeline.
The final product should look like this:
Update your pipeline YAML with a PowerShell task with
- task: PowerShell@2
inputs:
targetType: 'inline'
script: 'nuget push $(Build.ArtifactStagingDirectory)\*.nupkg -ApiKey $(myNuGetApiKey) -Source https://api.nuget.org/v3/index.json'
You don't have to change anything in this task. It will work with any standard way of NuGet packing provided by Azure DevOps.
Publish your updated yaml
pipeline and you are good to go.
trigger:
- master
pool:
vmImage: 'windows-latest'
steps:
- task: NuGetToolInstaller@1
inputs:
versionSpec: '5.7.0'
checkLatest: true
- task: DotNetCoreCLI@2
inputs:
command: 'build'
projects: '**/YourProjectNameOr*ForAll.csproj'
- task: NuGetCommand@2
inputs:
command: pack
packagesToPack: '**/YourProjectNameOr*ForAll.csproj'
- task: PowerShell@2
inputs:
targetType: 'inline'
script: 'nuget push $(Build.ArtifactStagingDirectory)\*.nupkg -ApiKey $(myNuGetApiKey) -Source https://api.nuget.org/v3/index.json'
- task: PowerShell@2
inputs:
targetType: 'inline'
script: 'nuget push $(Build.ArtifactStagingDirectory)\*.snupkg -ApiKey $(myNuGetApiKey) -Source https://api.nuget.org/v3/index.json'
Note: The second task is for publishing a symbol package. If your project doesn't support the source link, you can omit this task. This article from Karam Nandwani, the NuGet Program Manager, states that botch packages, *.nupkg
and *.snupkg
will by published automatically by one nuget command, but it's true. At least for now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With