Jenkins

Automating software development process using Jenkins.

Creating a VM using VirtualBox

image.png

image.png

Tick the checkbox with Skip Unattended installation. (Otherwise the terminal cannot be opened: This is an error with ubuntu 22.04 or virtualbox version.)

image.png

After clicking next you can select the Memory and no. of processors. Then install and create the virtual machine.

For further information refer this video: https://www.youtube.com/watch?v=nvdnQX9UkMY

Optional: Install guest additions (If skip unattended installation)

Guests Additions helps user to do tasks such as copy and paste from host-guest/ guest-host, resize the window size. It helps a lot when copying and transferring between guest and host. This gets installed automatically in the unattended installation. Since, it is skipped we have to install guest additions manually. 

$ sudo apt update
$ sudo apt install -y build-essential linux-headers-$(uname -r)

image.png

image.png

$ ./autorun.sh

After finish executing, restart the VM. Guests Additions will now be working!

Installing Prerequisites

Step 1: Install Java

image.png

Install java on the virtual machine using the following commands in the terminal.

$ sudo apt-cache search openjdk
$ sudo apt install openjdk-17-jdk -y
$ java -version

After running above command you should see something like this:

image.png

Step 1: Install Git

image.png

To install Git on your machine, run the following command.

$ sudo apt-get install git

After installing check if it is installed by running the following command.

$ git --version

Installing Jenkins

Go to Jenkins official website and download Jenkins for Ubuntu/debian. https://www.jenkins.io/download/

image.png

Then run the commands that is shown in the page. It should look something like below:

image.png

NOTE: Don't need to run the following command since java is already installed previously.

$ sudo apt-get install fontconfig openjdk-17-jre

After successfully installing Jenkins, run the following command to start Jenkins.

$ sudo systemctl start jenkins

To see if Jenkins is running, run the following command.

$ sudo systemctl status jenkins

Then you will get something like this:

image.png


IMPORTANT: Copy the password from above, you will need it when setting up Jenkins. 

Setting up Jenkins

image.png

image.png

Pipelines in Jenkins

Jenkins Pipelines are a powerful way to automate the software development lifecycle by defining CI/CD workflows as code. They allow you to automate tasks like building, testing, and deploying applications in a structured, repeatable, and scalable manner. Pipelines provide visualization of the workflow stages, support complex scenarios with branching and parallel execution, integrate easily with other tools, and enhance consistency, reliability, and speed in the delivery process, reducing manual errors and increasing efficiency.

Creating a simple pipeline

To create a simple pipeline go to the repository directory and create a text file named "Jenkinsfile". Inside the file copy and paste the below groovy script. This is a simple groovy script which prints some statements in each stage of the build. 

pipeline {
    agent any

    stages {
        stage('Build') {
            steps {
                echo 'Building the Application...'
            }
        }
        stage('Test') {
            steps {
                echo 'Testing the Application ...'
            }
        }
        stage('Deploy') {
            steps {
                echo 'Deploying the Application...'
            }
        }
    }
}

Now check status of jenkins using the following command.

$ sudo systemctl status jenkins

if it is active then go to jenkins running url (default is localhost:8080). if it is not active run the following command and start jenkins.

$ sudo systemctl start jenkins

image.png

 

 

 

 

 

 

image.png

image.png