Alex's Coding Blog
  • home
  • about
  • projects
  • contact

Blog

Connecting to Gitlab's private Nuget registry

  • June 03, 2024 March 07, 2025
  • by Alexander

Running a nuget registry for your project might be a good solution for a small project, however the setup is not that smooth as expected.

Reading the official documentation can be misleading. As in my case, for example, I use gitlab version 16.x, personal access tokens (PAT) is not longer a valid way to authorise agains nuget registry.

Starting from version 13, the working way is to use Deploy tokens.

Nuget registry is enabled by default on project level and on group level. Reasonable way to work is to push packages at project level and read a nuget "feed" on group level.

Pushing a package to registry

To Push the project add the following step to your .gitlab-ci.yaml:

script:  
 - dotnet build --configuration Release  
 - dotnet pack -p:PackageVersion=${VER} -o $PWD/nuget  
 - 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 "$PWD/nuget/\*.nupkg" --source gitlab  

Create a Deploy Token

On the left sidebar find your group
Select Settings > Repository.
Expand Deploy tokens.
Select Add token.
Enter your token details and check "read_package_registry" permission.

Registering you Nuget server as a source

You have two options adding new Nuget source to a project:

Add source with command line

dotnet nuget add source https://gitlab.yourdomain.com/api/v4/projects/${PROJECT_ID}/packages/nuget/index.json" --name gitlab --username nuget_reader --password <Your Deploy Token> 

Add source to nuget.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
    <add key="gitlab" value="https://gitlab.yourdomain.com/api/v4/groups/{PROJECT_ID}/-/packages/nuget/index.json" />
  </packageSources>
  <packageSourceCredentials>
    <gitlab>
      <add key="Username" value="nuget_reader" />
      <add key="ClearTextPassword" value="Your Deploy Token" />
    </gitlab>
  </packageSourceCredentials>
</configuration>
 
How-to

🚀 Turbocharge Your Kubernetes Cluster with my Terraform Kits! 🚀

🌟 Slash deployment time and costs! Discover the ultimate solution for efficient, cost-effective Kubernetes Terraform Kits. Perfect for DevOps enthusiasts looking for a reliable, scalable setup.

Learn More about Terraform Kits for AKS,EKS and GKE

Alexander Lvovich

Solution Architect & Software Developer | Automating & Scaling Infrastructure

💡 Working with Kubernetes, Istio, and DevOps. Got questions? Feel free to reach out!

Share on:

No comments are allowed for this post

Recent Posts

  • Securing Web Services Against Unwanted Traffic with NGINX
  • Optimizing API by Offloading Responsibilities to an API Gateway
  • How to Clean Up Local Branches of Remote Merged Branches
  • Resolving Namespace Overriding in Argo CD with Kustomize
  • Why Istio?

Categories

  • Azure
  • Architecture
  • .NET Core
  • Certification
  • DevOps
  • How-to
  • Azure Functions
  • Serverless
  • Cosmos DB
  • Security
  • Thoughts
  • Kubernetes
  • Istio
© Copyright 2025, Alexander Lvovich. Theme by Colorlib
I use cookies and similar technologies on our website to enhance your browsing experience and analyze website traffic. By clicking "Accept," you consent with my Privacy Policy to the use of these technologies.
Accept