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
- Once you have clicked on Manage Jenkins, you will be redirected to the setup and configuration of Jenkins.
- Click on Plugins
- Once you are in the main page of plugins, click on Available Plugins
- In the search bar, search for JFrog
- 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
- 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
- Once you are in the credentials page, click on Add Credentials
- 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
Configure 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
- 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
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
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
- 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
- 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
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
- Click on JFrog-CLI, then click on Build Now
- Click on the running build from the left hand side, in my case I have clicked on #7
- Click on Console Output
- 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
- Show the JFrog CLI configuration
- Ping Artifactory
- Create a new file “test-file”
- Add the file into the repository my-repo
- Download the file into the Jenkins server
- 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
You can also verify that the file test-file has been added to the repository as seen below