Sunday, June 19, 2022

JFrog Artifactory setup integration with Jenkins

 Hello Dear DevOps/DevSecOps engineers and automation team members. Today we will experiment on JFrog Artifactory integration with Jenkins. To do this we need to break down the task into two phases in the first phase we will do JFrog Artifactory setup. after that next phase we will do integrate it in Jenkins.

Pre-requisites:

    1. Virtual Boxes or VM instance on the Cloud  is the basic requirements

On the AWS Cloud: An AWS t2.small EC2 instance (Linux) if other cloud please select at least 2GB RAM providing instance. Open port 8081 and 8082 in the Security Group or on the firewall allow ports.

Vagrant boxes for Jenkins and jfrog artifactory

On premises setup using Vagrant
# Ubuntu boxes for Jenkins and Jfrog
Vagrant.configure("2") do |config|
    config.vm.provider "virtualbox" do |vb|
        vb.memory = "4096"
    end
    
    config.vm.define "master" do |master|
        master.vm.box = "ubuntu/focal64"
        master.vm.network "private_network", ip: "192.168.33.100"
        master.vm.hostname = "master.vybhava.com"
    end
    
    config.vm.define "jfrog" do |jfrog|
        jfrog.vm.box = "ubuntu/focal64"
        jfrog.vm.network "private_network", ip: "192.168.33.110"
        jfrog.vm.hostname = "jfrog.vybhava.com"
    end
end

2. The 'master' box intended to have installed with latest Jenkins on it.

3. The other box jfrog instance we need to install the JFrog Artifactory.(Below section dedicated for installation of JFrog Artifactory)

4. You must have GitHub account setup ready for this experiment

5. Jenkins Plugins we must install -- deploy artifacts, Artifactory

JFrog Artifactory integration with Jenkins CI/CD


What is JFrog Artifactory all about?

JFrog Artifactory is the single solution for housing and managing all the artifacts, binaries, packages, files, containers, and components for use throughout your software supply chain.

Why JFrog?

  • It's Frictionless
  • unified management of your software supply chain artifacts

Benefits of JFrog

  • Binary lifecycle management
  • Global scale availability
  • Package proxying
  • Secured Binaries
  • Repository optimization and flexibility
  • artifacts delivery to the edge (CDN, PDN)

How to install JFrog Artifactory 7 on Ubuntu?

In the following we do step-by-step installation on and configure JFrog.

Step 1: Install Java

Login to EC2 Ubuntu instance and switch user as a root user and check for Java if it is not exists then install Java as mentioned below

java -version #Check JDK availability
# If not install JDK 
# for RHEL/CentOS
yum install java-1.8* -y 
# for Ubuntu
apt install -y openjdk11 
# confirm it
java -version 


Step 2: Create jfrog user

Best practice to have a dedicated user as 'jfrog' for security purpose isolating with other users data should not have any issues during their clean up process.
sudo useradd -m -d /opt/jfrog -U -s /bin/false jfrog
id jfrog


Step 3: Download and Extract JFrog Artifactory


There are two optionw we have for Download  the JFrog Artifactory packages onto /tmp/ directory.
For Latest version of  JFrog Artifactory OSS download it from here [I've selected this choice]
For Older  Stable versions of  JFrog Artifactory OSS are available for download it from here

  cd /tmp; wget tar.gz option download the file.
  
extract artifactory tar.gz file if we go for older version then we need to use unzip utility. 
apt install -y unzip #Generally on AWS Ubuntu you need to install unzip utility

# JFrog 6.x
sudo unzip jfrog*.zip "artifactory-oss-6.23.3" -d "/opt/jfrog"
sudo chown -R jfrog:jfrog /opt/jfrog/
sudo chmod -R u+x /opt/jfrog/bin

# JFrog 7.x
sudo tar xzvf jfrog*tar.gz -C /opt/jfrog --strip-components=1
sudo chown -R jfrog:jfrog /opt/jfrog/
sudo chmod -R u+x /opt/jfrog/app/bin

Go inside JFrog installed path then go to the bin directory and start the services
cd /opt/jfrog/bin
./artifactory.sh start
JFrog Artifactory 6.x running on the Ubuntu as normal Tomcat embedded server start command as shown below.

Jfrog Artifactory 6 start command execution

On the JFrog Artifactory 7.x directory structure changed you can see : 
JFrog after extraction of the installer file


Below given will be required for Production environment [OPTIONAL] Creating a systemd service for artifactory You can create sudo nano /etc/systemd/system/artifactory.service file content
[Unit]
Description=Setup Systemd script for Artifactory in Tomcat Servlet Engine
After=network.target

[Service]
Type=forking
GuessMainPID=yes
Restart=always
RestartSec=5
PIDFile=/var/opt/jfrog/run/artifactory.pid
ExecStart=/opt/jfrog/artifactory/bin/artifactoryManage.sh start
ExecStop=/opt/jfrog/artifactory/bin/artifactoryManage.sh stop
User=artifactory
Group=artifactory
LimitNOFILE=32000

[Install]
WantedBy=multi-user.target
Alias=artifactory.service

Reload the systemd daemon so that it becomes aware of the new service:
sudo systemctl daemon-reload

You can then start the artifactory service by typing:
sudo systemctl start artifactory
Check the status using :
sudo systemctl status artifactory

To enable artifactory at the time of starting up box with the systemd, run the following command:
sudo systemctl enable artifactory  

Step 4: Access JFrog Artifactory URL 

Now all set to access the JFrog artifactory from the browser with 8081 default port.
http://JFROGPUBLICIP:8081

JFrog Artifactory Welcome Screen


To load the Artifactory page it might take few seconds. After that there will be a Welcome screen, and next Set Admin Password where you need to provide new password, confirm password retype.

Reset the Artifactory Credentials



Skip the proxy server configuration for this experiment. But for Organizations require to use that option as well. 

Next, Create Repository select "Maven" option. Once it is done, it will create 5 default repositories. Two of them will be local and two for remote access and one will be the virtual repository. Click on Finish.

Now we all set for the Artifactory use in the Jenkins. In the left side select Artifact Repository browser choose the build info.

Jenkins Artifactory integration


Navigate to Manage plugin in the availability tab search for "Artifactory" and in the bottom click on the "Install it without re-start".

How to Configure system -  JFrog Artifactory in Jenkins?

1. In Jenkins Dashboard, Go to Manage Jenkins, Click on Configure system. Look for JFrog Artifactory section, click on Add Artifactory Server.
2. JFrog Artifactory Configuration
 a. Please enter some name for server_id like jfrog-artifactory-id
    Enter Artifactory URL like given below: http://public_dns_name:8081/artifactory

   On the JFrog Artifactory 7.x the port 8081 will be redirected to 8082 which is one more step in the    securing the Artifactory access than previous version. Hence if you are running JFrog Artifactory 7.x use the following URL: http://public_dns_name:8082/artifactory
  b. Please enter your credentials like example here :  admin/Admin123 as credentials
  c. Click on Test connection to verify everything is right. You should get the message like below:
Found Artifactory version that is connected to.

JFrog Artifactory Configuration in Jenkins

Create Job for Archive Artifacts

There can be multiple artifacts packaged within a pom.xml definition. You may get single war file or jar file or else set of its dependencies .jar files as bundle. These artifacts can be varies from release to release versions. Which you can observe in the JFrog Artifactory once they are pushed to Artifactory server. Archive artifacts task can be performed with any type of projects. Here I will explore and show with Free Style job and Maven Projects.

Let's see with Freestyle project
  1. You can choose an existing or a new Freestyle job configuration. Here I've chosen new with name "ArchiveArtifacts-Free"
  2. In the Source code management section Chose Git and enter the GIT URL as per your project needs
  3. Go under Build Environment section Select Maven3-Artifactory Integration, You need to confirm the Artifactory server details and provide the local repository details that depends on Release repo or Snapshot repo names.
  4. In the Build section Invoke Artifactory Maven3 and under that Chose Goals: clean install
  5. Save the configuration and click on the "Build Now" to execute this job


6. Enter value as below, MyWebApp/pom.xml as root POM and target goal can be "clean package" but here you have to give "install"


7. Now click on Build, Jenkins should build using Maven and upload WAR file into Artifactory.

8. Login to JFrog Artifactory, Click on left  Artifactory --> Artifacts



That's it folks! Enjoy your automation task with JFrog Artifactory repos 😜

No comments:

Categories

Kubernetes (24) Docker (20) git (13) Jenkins (12) AWS (7) Jenkins CI (5) Vagrant (5) K8s (4) VirtualBox (4) CentOS7 (3) docker registry (3) docker-ee (3) ucp (3) Jenkins Automation (2) Jenkins Master Slave (2) Jenkins Project (2) containers (2) create deployment (2) docker EE (2) docker private registry (2) dockers (2) dtr (2) kubeadm (2) kubectl (2) kubelet (2) openssl (2) Alert Manager CLI (1) AlertManager (1) Apache Maven (1) Best DevOps interview questions (1) CentOS (1) Container as a Service (1) DevOps Interview Questions (1) Docker 19 CE on Ubuntu 19.04 (1) Docker Tutorial (1) Docker UCP (1) Docker installation on Ubunutu (1) Docker interview questions (1) Docker on PowerShell (1) Docker on Windows (1) Docker version (1) Docker-ee installation on CentOS (1) DockerHub (1) Features of DTR (1) Fedora (1) Freestyle Project (1) Git Install on CentOS (1) Git Install on Oracle Linux (1) Git Install on RHEL (1) Git Source based installation (1) Git line ending setup (1) Git migration (1) Grafana on Windows (1) Install DTR (1) Install Docker on Windows Server (1) Install Maven on CentOS (1) Issues (1) Jenkins CI server on AWS instance (1) Jenkins First Job (1) Jenkins Installation on CentOS7 (1) Jenkins Master (1) Jenkins automatic build (1) Jenkins installation on Ubuntu 18.04 (1) Jenkins integration with GitHub server (1) Jenkins on AWS Ubuntu (1) Kubernetes Cluster provisioning (1) Kubernetes interview questions (1) Kuberntes Installation (1) Maven (1) Maven installation on Unix (1) Operations interview Questions (1) Oracle Linux (1) Personal access tokens on GitHub (1) Problem in Docker (1) Prometheus (1) Prometheus CLI (1) RHEL (1) SCM (1) SCM Poll (1) SRE interview questions (1) Troubleshooting (1) Uninstall Git (1) Uninstall Git on CentOS7 (1) Universal Control Plane (1) Vagrantfile (1) amtool (1) aws IAM Role (1) aws policy (1) caas (1) chef installation (1) create organization on UCP (1) create team on UCP (1) docker CE (1) docker UCP console (1) docker command line (1) docker commands (1) docker community edition (1) docker container (1) docker editions (1) docker enterprise edition (1) docker enterprise edition deep dive (1) docker for windows (1) docker hub (1) docker installation (1) docker node (1) docker releases (1) docker secure registry (1) docker service (1) docker swarm init (1) docker swarm join (1) docker trusted registry (1) elasticBeanStalk (1) global configurations (1) helm installation issue (1) mvn (1) namespaces (1) promtool (1) service creation (1) slack (1)