top of page

LetsDevOps: Setup Jfrog Artifactory with GitLab CI/CD. Buid and Publish Package to Jfrog Artifact.

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

Workflow


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.




Step 2: Once the Repository created click on Set Me Up and select the package type. I will select Nuget in my case.



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.


Step 4: Create below variables in GitLab CI/CD and use the value from above step.

  1. JFROGSource

  2. JFROGPassword

  3. JFROGUsername




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.



Additional Commands.


dotnet nuget list source --> List all the Nuget Sources
dotnet nuget remove source <Name> --> Remove the Source with Name

Demo







bottom of page