Friday, November 15, 2024
Google search engine
HomeGuest BlogsDocker – Continuous Integration

Docker – Continuous Integration

In this post, we will see how to make Continuous Integration using Jenkins. In the previous post, we have seen how to install docker and the basic terminology and how to create an application using docker. With the help of Continuous Integration we can “Build”, “Test”, and “Package” our application.

For this, we need to make a Continuous Integration Pipeline. You can practice the below implementation with any preferred language of your application. For this post, we will be making a continuous integration pipeline for a java project. We have used the following project.

Continuous Integration Pipeline:

Setup of Jenkins:

Follow the below steps to setup Jenkins:

Step 1: Initial Images using the below command:

docker images

Initial docker images

Step 2: Use the below command to pull the Jenkins Image:

docker pull jenkins/jenkins

Pulling the Jenkins image from docker

Step 3: Use the below command to run the Jenkins image in a container made at port 1024 in localhost (make sure that the container is running in docker)

docker container run -it -u root -p 1024:8080 jenkins/jenkins:latest /bin/bash

Here the container is running at port 1024 in our local system and 8080 is running in the container.

Running container at port 1024

Step 4: Use the below command to update the container image:

apt-get update

Updating the Docker image

Step 5: Now use the below command to install the net-tools:

apt install net-tools

Installing net-tools

Step 6: As it is a Java-based project installing “Maven” inside the container. (If it was a Nodejs based project we have to install node, git)

apt-get install maven

Installing maven

Step 7: Install zip to get the bundled file during the package phase. Below is the command for the same

apt-get install zip

Installing zip

Step 8: Now run the Jenkins container at port 1024 using the below command:

jenkins.sh

Running Jenkins at port 1024

Creating Custom user-id Details:

Follow the below steps to create custom users:

  • Copy the password given in the terminal and enter it into the Jenkins running at localhost:1024
  • Install all the required plugins for the project
  • After that configure the global security so that you can add custom users to Jenkins.
  • Jenkins is not ready for the first build job.

login into Jenkins

Install the recommended plugins:

Installing the suggested plugins

Creating first user-id (this step can be avoided and the user can continue with the admin login done before):

creating first user-id

Instance configuration shows the port where it’s working on the browser:

Jenkins Setup Completed:

  • Click on start using Jenkins

Jenkins is ready to go!

Initial view:

The initial view of Jenkins 

Step 8: Now go to the Manage Jenkins section and click on “Configure Global Security” so as to enable other users to sign up. So, now we can add new users to this Jenkins.

Step 9: Installing the required plugins required for the java project under the “Manage plugin section” that is “Pipeline Maven”, “AdoptopenJDK” and “Maven Integration”

Installing maven plugin

Installing AdoptopenJDK plugin

Installing Maven Integration plugin

Now, whenever there is a change/editing in the source code there will always be a new version of the commit. For each commit we need to trigger a build and build will trigger test and test will trigger package. So, we need to create a pipeline between Build-Test-Package

First making independent files for build, test, and package then we will integrate all three together thus creating a pipeline.

Build:

Make first build job by clicking on the “New Item” option in the sidebar and giving the name of the item and selecting “Maven Project” as a Java project.

Build

Under source code management enter the git repository link with “.git” as an extension as shown below:

entering git repository link

Goals and options(build): clean install

goals and option for build

After building we get the output in the console

TEST:

Same steps to be followed as done in build phase only difference is that under goals and option we write the command “test”

test file

goals and options for test

After configuration builds the test phase.

test console output

Package:

Same steps to be followed as done in build phase only difference is that under goals and option we write the command “package” and

Under post-build actions choose: “File to archive”—>**/target/*.jar (write this where the bundled file will be stored in this location)

After configuration build the package phase.

package file

package goals and options

Under post-build action choose “Files to archive” then write the location where the package file will be stored

archiving the artifacts

package output

Integration of “Build-Test-Package”:

For now, all these 3 files are independent we need to integrate them.  

 1. Integrating “build” file to “test” file

Integration of build to test file

Save it after making the above changes.

Test file connected to build file

2. Integrating “test” file to “package” file

Integration of package to test file

Save it after making the above changes.

Both build and package file connected to test file

After integrating whenever there is a change/edit in the project it will trigger the build phase. The build phase will trigger the test phase and the test phase will trigger the package phase.

Hence Continuous Integration Pipeline is made.

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments