ARTIFACTORY: How to Use JFrog CLI in Jenkins Using JFrog Plugin

ARTIFACTORY: How to Use JFrog CLI in Jenkins Using JFrog Plugin

AuthorFullName__c
Afeef Khateeb
articleNumber
000005814
FirstPublishedDate
2023-07-13T10:17:31Z
lastModifiedDate
2025-05-14
VersionNumber
10
 
Implementation Steps
 
  • Install JFrog Plugin on Jenkins
  • Create Credentials on Jenkins to connect it with JFrog
  • Configure JFrog Platform
  • Review a sample CLI project
  • Create JFrog CLI Global tool configuration
  • Run a sample job
     
Install JFrog Plugin on Jenkins

The first step is to install JFrog Jenkins plugin by following the steps below 

  • Go to your Jenkins web page
    • http://JENKINSURL:8080 or if you are using a reverse proxy make sure to remove the 8080 port or change the http to https
    • Once you are in the homepage of Jenkins, click on manage Jenkins as seen in the following screenshot

User-added image

  • Once you have clicked on Manage Jenkins, you will be redirected to the setup and configuration of Jenkins. 
  • Click on Plugins

User-added image

  • Once you are in the main page of plugins, click on Available Plugins 
  • In the search bar, search for JFrog 

User-added image

  • Click on Download now and install after restart
  • Once it is installed, restart Jenkins by selecting Restart Jenkins when installation is complete and no jobs are running


User-added image

  • Verify that Jenkins is installed by going to Manage Jenkins → Plugins → installed Plugins
     
Create Credentials on Jenkins to connect it with JFrog

In this section we are going to create credentials that will be used in the upcoming step to connect it with JFrog Platform 

  • Click on Manage Jenkins 
  • Click on Credentials
  • Select Global 

User-added image

  • Once you are in the credentials page, click on Add Credentials

User-added image

 

  • The selection will be username and password
  • Insert a username based on a username created in JFrog 
  • Insert a password based on your username’s password 
  • In the ID section, put an ID to differentiate it from other credentials, in our case we will put JFrog
  • Last set click on Create

User-added imageConfigure JFrog Platform

 
 

Once we have created the credentials, we will connect Jenkins with JFrog by following these steps: 

  • Click on Manage Jenkins 
  • Go to system configuration → System

User-added image

  • Click on Add JFrog Platform Instance
  • In the Server ID section type and ID to distinguish between other IDs inserted. You can insert “artifactory-1”
  • Insert the URL/IP address of the JFrog Platform. 
  • In the credentials section, click on the list and select the credentials we did in the step before. 
  • Select Allow HTTP Connection if you want to bypass HTTPS 
  • Click on Apply to save your settings


User-added image

Review a sample CLI project

Once the connection is set, we will start adding builds, and inside the builds we will add the JFrog CLI command to control JFrog Platform

  • From the main page, click on New Item 

User-added image

Insert a new name for the item, in our case we can insert JFrog-CLI, and select Pipelines, then click on OK.  
Once the Build is added, scroll down to reach Pipeline section 

User-added image

  • Here we will insert the following commands 
pipeline{
    agent any
    tools {
        jfrog 'jfrog-cli-latest'
    }
    stages {
        stage ('Testing') {
            steps {
                jf '-v' 
                jf 'c show'
                jf 'rt ping'
                sh 'touch test-file'
                jf 'rt u test-file my-repo/'
                jf 'rt bp'
                jf 'rt dl my-repo/test-file'
            }
        } 
    }
}

 

 

Explanation 

In the above example we are uploading and downloading generic files. as follows 

tools {
        jfrog 'jfrog-cli-latest'
    }

 

Means that we are defining a new tool called jfrog-cli-latest to download it from release.jfrog.io, which is going to be defined in the coming section. 

Next we will start by defining a stage in Jenkins, which is a Testing stage, and then inserting commands which are JFrog CLI commands. Each command has a description besides it 
 

stages {
        stage ('Testing') {
            steps {
		   #Show the version of JFrog CLI used 
                jf '-v' 
		   #Show the configuration used to connect to JFrog Platform 
                jf 'c show'
		   #in this command we are pinging the artifactory to see if it is alive 
                jf 'rt ping'
		   #In this command we are creating a new file 
                sh 'touch test-file'
#In this command we are adding the new file created previously inside the my- repo repository 
                jf 'rt u test-file my-repo/'
             	   #Publish the build-info into Artifactory.
   jf 'rt bp'
   #Download the test-file
                jf 'rt dl my-repo/test-file'

            }
        } 
    }
}

 

Create JFrog CLI Global tool configuration


Once we have added the pipeline, we will start adding the tool “jfrog-cli-latest” in Jenkins to make sure that Jenkins understands what this tool is for and how to connect it to the JFrog Platform once this tool is called. 

To add this tool copy “jfrog-cli-latest” and then follow these steps 

  • Go to Manage Jenkins 
  • Go to system configuration section → Tools 
  • Scroll Down until the end 

User-added image

  • Click on Add JFrog CLI
  • Give it the same name as the “jfrog-cli-latest” without the two quotations 
  • Leave the version empty as we want to install the latest version from the releases.jfrog.io 

User-added image

Run a sample job

Once you have configured the following:

  • Create Credentials on Jenkins to connect it with JFrog
  • Configure JFrog Platform
  • Review a sample CLI project
  • Create JFrog CLI Global tool configuration

Then you are good to run the job by following these steps 

  • Go to the main homepage, where you will see the job as follows 

User-added image

  • Click on JFrog-CLI, then click on Build Now 

User-added image

  • Click on the running build from the left hand side, in my case I have clicked on #7

User-added image

  • Click on Console Output 

User-added image

  • You will see the result of the job if it is successful of not

Once the job is done successfully, you will see the following result 

  • Output the version of JFrog CLI

User-added image

  • Show the JFrog CLI configuration

User-added image

  • Ping Artifactory 

User-added image

  • Create a new file “test-file”

User-added image

  • Add the file into the repository my-repo

User-added image

  • Download the file into the Jenkins server 

User-added image

  • You can find the file downloaded in “/var/lib/jenkins/workspace/JFrog-CLI”

You can also verify that the build ran successfully from the green image on the left hand side 
User-added image

You can also verify that the file test-file has been added to the repository as seen below 
User-added image