Docs feedback: Nuget publish CICD example does not work
https://docs.gitlab.com/ee/user/packages/nuget_repository/#publish-a-nuget-package-by-using-cicd
I took the example, and made minimal changes so there was a .net 8 new razor library to push.
I tried several other manual options, but none of them worked. So, I tried the option below to try and eliminate every variable I could. The resulting failure suggests something is missing in the example, or in the troubleshooting section. I'm on a self hosted v17.1.2-ee instance
stages:
- deploy
image: mcr.microsoft.com/dotnet/sdk:8.0
deploy:
stage: deploy
script:
- cd ./RazorClassLibrary1/RazorClassLibrary1
- dotnet pack -c Release
- dotnet nuget add source "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/nuget/index.json" --name gitlab --username gitlab-ci-token --password $CI_JOB_TOKEN --store-password-in-clear-text
- dotnet nuget push "bin/Release/*.nupkg" --source gitlab
only:
- main
environment: production
tags:
- openshift
I get the following log. I am a project and group owner.
$ cd ./RazorClassLibrary1/RazorClassLibrary1
$ dotnet pack -c Release
Determining projects to restore...
Restored /builds/BWH_Path_Informatics/gitlab-testing/RazorClassLibrary1/RazorClassLibrary1/RazorClassLibrary1.csproj (in 4.07 sec).
RazorClassLibrary1 -> /builds/BWH_Path_Informatics/gitlab-testing/RazorClassLibrary1/RazorClassLibrary1/bin/Release/net8.0/RazorClassLibrary1.dll
The package RazorClassLibrary1.1.0.0 is missing a readme. Go to https://aka.ms/nuget/authoring-best-practices/readme to learn why package readmes are important.
Successfully created package '/builds/BWH_Path_Informatics/gitlab-testing/RazorClassLibrary1/RazorClassLibrary1/bin/Release/RazorClassLibrary1.1.0.0.nupkg'.
$ dotnet nuget add source "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/nuget/index.json" --name gitlab --username gitlab-ci-token --password $CI_JOB_TOKEN --store-password-in-clear-text
Package source with Name: gitlab added successfully.
$ dotnet nuget push "bin/Release/*.nupkg" --source gitlab
warn : No API Key was provided and no API Key could be found for 'https://[redacted]/api/v4/projects/1380/packages/nuget'. To save an API Key for a source use the 'setApiKey' command.
Pushing RazorClassLibrary1.1.0.0.nupkg to 'https://[redacted]/api/v4/projects/1380/packages/nuget'...
PUT https://[redacted]/api/v4/projects/1380/packages/nuget/
Forbidden https://[redacted]/api/v4/projects/1380/packages/nuget/ 265ms
error: Response status code does not indicate success: 403 (Forbidden).
Usage: dotnet nuget push [arguments] [options]
Arguments:
[root] Specify the path to the package and your API key to push the package to the server.
Options:
-h|--help Show help information
--force-english-output Forces the application to run using an invariant, English-based culture.
-s|--source <source> Package source (URL, UNC/folder path or package source name) to use. Defaults to DefaultPushSource if specified in NuGet.Config.
-ss|--symbol-source <source> Symbol server URL to use.
-t|--timeout <timeout> Timeout for pushing to a server in seconds. Defaults to 300 seconds (5 minutes).
-k|--api-key <apiKey> The API key for the server.
-sk|--symbol-api-key <apiKey> The API key for the symbol server.
-d|--disable-buffering Disable buffering when pushing to an HTTP(S) server to decrease memory usage.
-n|--no-symbols If a symbols package exists, it will not be pushed to a symbols server.
--no-service-endpoint Does not append "api/v2/package" to the source URL.
--interactive Allow the command to block and require manual action for operations like authentication.
--skip-duplicate If a package and version already exists, skip it and continue with the next package in the push, if any.