How Jenkins Can Transform Your DevOps Workflow

How Jenkins Can Transform Your DevOps Workflow

Jenkins is an automation server used for Continuous Integration(CI) and Continuous Delivery(CD) practices .

Prerequisites

  • GitHub.

  • Linux basics.

  • Docker basics.

  • Connecting with ec2 instance.

Before Jenkins, the development process of an application often needed different teams like building, testing and deploying, which lead to delays and conflicts .Then, hero of our story ‘Jenkins‘ stepped in and eliminated the problems by automating the process of development and workflow.

Workflow Before Jenkins

  1. Development of code

  2. Manual Build process

  3. Manual Testing

  4. Manual Deployment

Workflow After Jenkins

  1. Development of code

  2. Automatic Build Trigger

  3. Automated Testing

  4. Continuous Integration

  5. Deployment Automation

  6. Monitoring and Feedback

Let’s know how to set up jenkins server in an ec2 instance .

Read this article for establishing connection between ec2 instance and windows .

Go through this article for acquiring basic knowledge on Docker .

All you need is pulling the jenkins image to operate on it.

Enter this command in your mobaxterm command line :
docker run -p 8080:8080 -p 50000:50000 -d -v jenkins_home:/var/jenkins_home -it jenkins/jenkins:lts

Frustated ? Let’s break down the command and understand it.

  • docker run —> Command used to run the jenkins image.

  • -p 8080:8080 —> Binds port 8080 in the host-machine to 8080 in the container

  • -p 50000:50000 —>Binds port 50000 in the host-machine to 50000 in the container ,this is for communication between jenkins master and its agents.

  • -v —> Used to denote volume.

  • -v jenkins_home:/var/jenkins_home —> Mounts a docker volume named jenkins_home to the path /var/jenkins_home inside the container ,i.e what ever changes made to jenkins image are stored in the path.

-d —> Denotes detached mode.

Note : Don’t forget to add the port 8080 to the inbound rules in the configuration of ec2-instance.

Type the following link to access your jenkins webpage.

EC2-IPADDRESS:8080

Use the command “docker logs CONTAINER-ID“ to get the password for unlocking jenkins .Proceed with common signup formalities in it ,there is no need of using correct details since the ec2 instance is ephemeral .And you are in jenkins UI ,where you can play around .

Let’s take a tour of jenkins UI ,there are different options like New item ,Build history and more which have their own special functionality .We will discuss about them in detail .On clicking the New item option ,you will be redirected to the below page ,which consists of different types of items.

Item Types

  1. Free style —> Suitable for Single job purpose.

  2. Pipeline —> Used for multiple jobs like building ,testing and deploying.

  3. Multibranch pipeline —> Suitable when you have different branches working on single project.

Let’s discuss each topic in detail ,with an example for each.

Free style

Let’s discuss free style job using an example ,consider you have a github repository which consists of java code .

Steps for setting free style job

  1. Create the Freestyle Job: Go to Jenkins Dashboard → "New Item" → Enter a name → Select "Freestyle Project" → Click "OK."

  2. Configure Source Code Management: In the "Source Code Management" section, choose "Git." Enter the GitHub repository URL.

  3. Add Build Steps: javac javaFile.java
    java javaFile

  4. Build : Click on build .

Open Console output to see output.


Pipeline

Steps for setting Pipeline job

  1. Click on New Item from the Jenkins dashboard.

  2. Enter a name for your job (e.g., Pipeline-job).

  3. Select Pipeline from the list of job types.

  4. Click OK.

  5. In the job configuration, set up the pipeline:

    General Settings

    • Add a description for the job (optional).

    • Check GitHub project if your code is hosted on GitHub, and provide the project URL.

Pipeline Settings

  1. Under Definition, choose one of the following:

    • Pipeline script: Write the pipeline directly in Jenkins.

    • Pipeline script from SCM: Use a Jenkinsfile from your source control (preferred for large projects).

I am using Pipeline script from SCM ,Use this link ,

  • Select the SCM type (e.g., Git).

  • Provide the repository URL.

  • Specify the branch (e.g., master).

  • Provide the path to the Jenkinsfile(e.g., Pipeline/Jenkinsfile).

Click on Build and go to console output and watch for logs.