How to configure Jenkins CI-CD For Publish NuGet Package to Azure Artifacts Private Package

 In blog

In this blog we are looking in how you can enable Continuous integration & Continuous delivery for Packages which are created in the azure DevOps artifacts.

In this blog we are talking about NuGet package So let’s get started.

Context

                        1.Prerequisite.  

                        2.Creation of feed & connection configuration.

                        3.Jenkins Configuration.

Prerequisite

We required Jenkins Installed & running on windows10, also need the access of the azure devops project where we need to create artifacts & publish.

Ensure the following Jenkins plugins are enabled:

Other than this Jenkins machine should have the NuGet installed, and it should be added to environment variable so we can access from cmd. You can find the NuGet from https://www.nuget.org/downloads .

This is the flow implemented in this post:

Graphical user interface, application, Teams  Description automatically generated

                                        Package CI-CD

Now everything has been setup so let’s create feed on azure devops and add those details in project,

I have created one project and click on the create feed,

Graphical user interface, text, application  Description automatically generated

                                                                    Fig.1

Add details like name, visibility to whom this access to Member of Azure AD, Specific people & specify the scope.

Once feed creation done click on the connect feed you can see different package,

Application  Description automatically generated with medium confidence

                                                                            Fig 2.

Go and select the nuget.exe you can see details as below, follow the steps as mentioned add those details to the root of the project.

Graphical user interface, text, application, email  Description automatically generated

                                                                      Fig 3.

Now let’s go back to Jenkins  create new project select the Freestyle Project,

Graphical user interface, text, application, email  Description automatically generated

                                                                               Fig 4.

Add the Source code details specify the URL, Credential’s & specify the branch 

Graphical user interface, text, application, email  Description automatically generated

                                                                                          Fig 5.

Now go and open the Jenkins Installed machine and find the default NuGet.config which usually stored in C:\Users\Admin\AppData\Roaming\NuGet.

Open cmd in the Jenkins machine and go to the nuget.exe directory and run this command

Text  Description automatically generated

                                                                                    Fig 6.

Specify the workspace and source package link which we have created in the azure artifacts and run the command it will ask for the authentication of azure ad user once you authenticate it will add package key and value in the default location of Nuget.config.

Also it will create PAT (Personal access token) to access Private Azure Artifacts which we have created in the Azure DevOps and add those details to nuget and configuration look like this,

Password will be your generated PAT which automatically add when you authenticate through Azure AD ID and Password. PAT will be difference for different users.

Once it done now go back to the Jenkins Job and run window batch commands first will restore and then build the project once it done will need to run pack and publish so on.

Graphical user interface, text, application, email  Description automatically generated

                                                                        Fig 7.

Now run this NuGet Pack and publish Commands,

                                                                         Fig 8.

Once this done run the Project and Our CI_CD Enable for the Private Package management in Azure DevOps Artifacts.

Why we have run restore command manually because it will add authentication key (username) and value (Password or PAT) in NuGet.config so than onwards it will not ask for authentication anymore and our Package will build and run deploy as commit happen to the Our Repository.

So that’s it for now hope you like the blog if you like share and leave comment if you have any question.Stay tuned for more updates. Goodbye. 

Recent Posts

Leave a Comment

Start typing and press Enter to search