Introduction
In this article we will learn to setup Jfrog with GitLab. After that we will build the nuget package and publish to Jfrog Artifactory.
What is Jfrog Artifactory
Package/Artifact Management tool. Its helps to store and share multiple version of Package/Artifact. Supports all the available package format, Like nuget,npm,maven,help etc..
Why we need Jfrog Artifactory
In some cases when you need to share the package/artifact with other teammates or Project Group.
UseCase
Jfrog Artifactory with GitLab.
Architecture
![](https://static.wixstatic.com/media/33586b_9f2118894d6e4584b3c23934fbf81fe7~mv2.png/v1/fill/w_71,h_34,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/33586b_9f2118894d6e4584b3c23934fbf81fe7~mv2.png)
Workflow
![](https://static.wixstatic.com/media/33586b_caafb02812a84b60851ac24aaef87544~mv2.png/v1/fill/w_77,h_16,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/33586b_caafb02812a84b60851ac24aaef87544~mv2.png)
Jfrog Integration
First we need to complete the configuration of Jfrog Antifactory with GitLab Runner.
Step 1: Login to Jfrog and Create Repository for your package type if that does not exist. In my case we created Repository of Nuget Package Type.
![](https://static.wixstatic.com/media/33586b_2301900edcc64f06975f20e53f217b26~mv2.png/v1/fill/w_49,h_32,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/33586b_2301900edcc64f06975f20e53f217b26~mv2.png)
Step 2: Once the Repository created click on Set Me Up and select the package type. I will select Nuget in my case.
![](https://static.wixstatic.com/media/33586b_f87af52bf81c42a987b08fd922eab481~mv2.png/v1/fill/w_49,h_29,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/33586b_f87af52bf81c42a987b08fd922eab481~mv2.png)
Step 3: Collect below info from the window. These command needs to run on the GitLab-Runner to setup the connection
This command needs to run once so that connection gets configured. We will run this through Pipeline not manually.
![](https://static.wixstatic.com/media/33586b_37a703e473864fe5950059609b599c34~mv2.png/v1/fill/w_46,h_33,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/33586b_37a703e473864fe5950059609b599c34~mv2.png)
Step 4: Create below variables in GitLab CI/CD and use the value from above step.
JFROGSource
JFROGPassword
JFROGUsername
![](https://static.wixstatic.com/media/33586b_cd14c7d8be25418b917e02296f2ae405~mv2.png/v1/fill/w_49,h_39,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/33586b_cd14c7d8be25418b917e02296f2ae405~mv2.png)
Setup Build Pipeline
Now lets build one sample application and further we will create the package and publish to Jfrog Artifactory.
Step 1: Include the antifactory setup information received in pervious step in pipeline. See for Example.
Note: Make sure the nuget is installed on GitLab Runner.
- nuget sources Add -Name Artifactory -Source $JFROGSource -username $JFROGUsername -password $JFROGPassword
- nuget setapikey$JFROGUsername:$JFROGPassword -Source Artifactory
Step 2: Complete pipeline with example.
stages:
- build
- package
- deploy
build-job:
stage: build
tags:
- "windows-runner"
script:
- nuget sources Add -Name Artifactory -Source $JFROGSource -username $JFROGUsername -password $JFROGPassword
- nuget setapikey $JFROGUsername:$JFROGPassword -Source Artifactory
- dotnet build $CI_PROJECT_DIR\BuildNugetPackage.sln /p:Configuration="Release"
- cd $CI_PROJECT_DIR
- nuget pack -properties version=1.0.2
- nuget push DeployPackage.1.0.2.nupkg -Source Artifactory
Step 3: Run the Pipeline.
Step 4: After successful execution we can comment nuget add sources. Since it is one time activity. The connection gets saved to GitLab-Runner.
Validate the Package
On successful execution you can see the package publish to Jfrog Antifactory.
![](https://static.wixstatic.com/media/33586b_fcaa0e2a89404c0490f4afea698a8d7d~mv2.png/v1/fill/w_62,h_49,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/33586b_fcaa0e2a89404c0490f4afea698a8d7d~mv2.png)
Additional Commands.
dotnet nuget list source --> List all the Nuget Sources
dotnet nuget remove source <Name> --> Remove the Source with Name