CI-Jenkins pipeline setup.

CI PIPELINE SETUP WITH VARIOUS TOOLS

You need to complete this project in one go.

Step 1 –

Create the Ec2 instance in AWS account with these parameters

EC2 type – Ubuntu t2.medium EBS volume – 30 GB Region – US-EAST-2

Step 2 – Connect to EC2 and Install all tools in that system as root user

To login as root user use command: sudo su

Step 3 – Install Jenkins on Ubuntu

Open below link and Just copy paste the entire commands from below link on command line window and run all commands:

https://github.com/yesicanvinayak/tools_installation_scripts/blob/main/jenkins.sh

After installation completion. Below screen will appear. First time select OK and second time cancel it.

Step 4 – Change the security group of ec2 instance

Step 5 – Sign Into Jenkins console

http://<EC2_PUBLIC _IP>:8080/

Step 6 – Get the Administrator password by hitting the below command:

cat /var/lib/jenkins/secrets/initialAdminPassword

Step 7 – Click on > Install all suggested plugins

Step 8 – Create first user

Click on Save and continue >> Click on Start using Jenkins

Step 9** – Create a pipeline Job

Click on New Item or Click on Create a job \> Both open same window.

Click on Pipeline and Write name.

Click on Ok.

Step 10 – Add pipeline script as SCM

Scroll down and click on Pipeline script and select \> Pipeline script from SCM

On SCM section select Git

Paste Your Repository URL >> https://github.com/yesicanvinayak/Java_app_3.0.git

Add "Branch Specifier" >> main >> then click on save

Step 11 – To Add the Plugins.

Click on "Dashboard"

-> Click on "Manage Jenkins" -> Click on "Plugins"

-> Click on "Available plugins"

-> Copy below-mentioned each name and paste it in the search box and click "select box"

  1. Sonar Gerrit 2) SonarQube Scanner 3) SonarQube Generic Coverage
    4)Sonar Quality Gates 5) Quality Gates 6) Artifactory 7) Jfrog

Click on "Install" at top right corner.

Wait till all success.

Step 12 – Setup Docker

Open below link and Just copy paste the entire commands from below link on command line window and run all commands:

https://github.com/yesicanvinayak/tools_installation_scripts/blob/main/docker.sh

Check docker.service is running and enabled using command:

sudo systemctl status docker.service

Press "q" to quite.

Check docker version.

docker -v

Step 13- Install SonarQube

Open below link and Just copy paste the entire commands from below link on command line window and run all commands:

https://github.com/yesicanvinayak/tools_installation_scripts/blob/main/sonarqube.sh

Check docker-container is running:
docker ps

Step 13 .1 -> Start docker container if it's not up

docker ps -a [ Get the container ID ]

docker start

Step 13.2 -> Login into sonar dashboard

Open browser and paste EC2-IP with port number > 9000
http://<EC2-IP>:9000

Username – admin

Password – admin

Click on "Login"

Change password and click on update.

Step 13.3 -> Create Sonar token for Jenkins

Sonar Dashboard -> Administration -> My Account -> Security -> Create token -> Save the token to some text file

Top right corner click on Icon "A" >> Click on "My Account"

-> Click on Security tab -> Create token write name and select options as shown in screenshot -> Click on generate. -> Copy token and Save the token to some text file

Step 13.4 -> Integrate Sonar to Jenkins

Sonar Dashboard -> Administration -> Configuration -> webhooks

Click on Create -> Add the below name and url and save

http://<EC2_IP>:8080/sonarqube-webhook/

-> Add the below name and url and save

http://<EC2_IP>:8080/sonarqube-webhook/

Step 14 – Install Maven:

Open below link and Just copy paste the entire commands from below link on command line window and run all commands:

https://github.com/yesicanvinayak/tools_installation_scripts/blob/main/Maven.sh

Check maven version using command:

mvn -v

Step 15 – Install TRIVY for docker image scan

Open below link and Just copy paste the entire commands from below link on command line window and run all commands:

https://github.com/yesicanvinayak/tools_installation_scripts/blob/main/trivy.sh

Check trivy version using command:
trivy version

Step 16 – Integrate All tools with Jenkins

-> Click on Jenkins "Dashboard" -> Manage Jenkins -> system configuration menu > Click on "System"

Step 16.1 -> ADD SONARQUBE

Ctrl+f -> Search for "sonar"

You will get "SonarQube servers" -> SonarQube installations -> Click on "add sonarqube" -> Add Name "sonar-api" and Server URL "http://18.217.249.180:9000" {<EC2-IP>:9000} (Remove / after 9000)

-> Click on "Save"

-> Again Click on Jenkins "Dashboard" -> Manage Jenkins -> system configuration menu > Click on "System"

Ctrl+f -> Search for "sonar"

You will get "SonarQube servers" -> SonarQube installations -> Click on "+Add" To add the token -> It will show "Jenkins"

-> Click on "Jenkins" -> New window will open -> In "Add Credentials" menu -> Under Kind -> Select Secret text -> In "Secret" section -> Add the sonar token from step-13.3 -> In "ID" section -> Give name of token as "sonarqube-api" -> Click on "Add"

-> Under "Server authentication token" -> select "sonarqube-api"

-> Click on "Save"

Step 17 - Add the docker HUB credentials ID Jenkins dashboard

-> Click on Jenkins "Dashboard" -> Manage Jenkins -> system configuration menu > Click on "System"

Ctrl+f -> Search for "Creden"

You will get "Credentials" -> Click on "Credentials"

-> Under Credentials -> In First line click on System -> click on global credentials

-> Click on "Add Credentials" On top right corner

-> ADD the docker hub credentials -> Username and password -> Under ID section add name as docker -> Click on create.

Step 18 – Add the Jenkins Shared library

Open your project on Github -> Check in your Project's Jenkinsfile @Library('my-shared-library') Add the same here.

On Jenkins UI-> Click on Jenkins "Dashboard" -> Manage Jenkins -> system configuration menu > Click on "System"

Ctrl+f -> Search for "Global pipeline"

You will get "Global pipeline Libraries" -> Click on "Add"

-> Add below data
Name - my-shared-library ->> Default version –> Write main

->> Then in Source Code Management write -> Git

-> In Project Repository add link-> https://github.com/yesicanvinayak/jenkins_shared_lib.git

-> Click on "Save"

Open your project on Github -> Check in your Project's Jenkinsfile @Library('my-shared-library') Add the same here.

Step 19 - Run pipeline and Check

-> Click on "Dashboard" -> Click on Pipeline name. (Java-app-ci-pipeline)

-> Click on "Build now"

-> You can see the below result.

-> Click on number #01

Go to docker hub account >> You can see image uploaded.

Stay in the loop with my latest insights and articles on cloud ☁️ and DevOps ♾️ by following me on LinkedIn https://www.linkedin.com/in/vinayak-salunkhe-devops-034a3a73/

I hope you enjoy the blog post!

If you find the blog helpful, please do like it and share it with your friends. If you have any doubts or questions related to the topics covered in the blog, feel free to ask them in the comments section. I’ll be more than happy to help!