Skip to main content

Experiment to Setup Jenkins and Demonstrating Continuous Integration

 Title: Setting up Jenkins and Demonstrating Continuous Integration

Objective:

The objective of this experiment is to set up Jenkins and demonstrate Continuous Integration (CI) by automating the build process of a simple Java project whenever changes are pushed to the version control repository.

Prerequisites:

  • Java Development Kit (JDK) installed on your system
  • Apache Maven installed on your system
  • Git installed on your system
  • Jenkins installed on a server or local machine

Experiment Steps:

Step 1: Install Java Development Kit (JDK)

  1. Download and install the latest JDK version compatible with your operating system.
  2. Set the JAVA_HOME environment variable to the JDK installation directory.

Step 2: Install Apache Maven

  1. Download the latest Apache Maven binary distribution from the official website (https://maven.apache.org/download.cgi).
  2. Extract the downloaded archive to a directory on your system.
  3. Set the MAVEN_HOME environment variable to the Maven installation directory.
  4. Add the Maven bin directory to the system's PATH variable.

Step 3: Install Git

  1. Download and install Git from the official website (https://git-scm.com/downloads).
  2. Configure Git with your username and email using the following commands:


git config --global user.name "Your Name"

git config --global user.email "you@example.com"


Step 4: Install Jenkins

  1. Download and install Jenkins on your server or local machine by following the official installation guide (https://www.jenkins.io/doc/book/installing/).
  2. Start the Jenkins server and access the Jenkins web interface using a web browser.

Step 5: Set up Jenkins for CI

  1. Access the Jenkins web interface (usually at http://localhost:8080) and complete the initial setup by providing the Administrator password and installing the recommended plugins.
  2. Create a new Jenkins pipeline project:
  3. Click on "New Item" on the Jenkins dashboard.
  4. Enter a name for the project (e.g., "MyJavaApp").
  5. Select "Pipeline" and click "OK."
  6. Configure the pipeline:
  7. Under the "Pipeline" section, choose "Pipeline script from SCM."
  8. Select "Git" as the SCM (Source Code Management) and provide the repository URL.
  9. Save the configuration.

Step 6: Create a Simple Java Project with Version Control

  1. Create a new directory for your Java project.
  2. Inside the project directory, create a new Java source file with a simple Java class (e.g., HelloWorld.java).
  3. Initialize Git in the project directory:


git init

  • Add the Java source file to the Git repository:

git add HelloWorld.java

  • Commit the initial version of the project:

git commit -m "Initial commit"

  • Create a remote repository (e.g., on GitHub, GitLab, or Bitbucket) and link it to the local repository:

git remote add origin <repository_url>

git push -u origin master


Step 7: Configure Jenkins to Trigger CI

  1. In the Jenkins pipeline project, click on "Build Now" to manually trigger the first build.
  2. Verify that the build is successful.

Step 8: Test CI by Pushing Changes

  1. Make some changes to the HelloWorld.java file.
  2. Commit the changes to the Git repository:

git add HelloWorld.java

git commit -m "Updated HelloWorld.java"

  • Push the changes to the remote repository:

git push origin master

  • Observe that Jenkins automatically triggers a new build due to the code changes.

Conclusion:

In this experiment, we successfully set up Jenkins and demonstrated Continuous Integration (CI) by automating the build process of a simple Java project whenever changes were pushed to the version control repository. Jenkins continuously monitored the repository for changes and automatically initiated the build, ensuring that the application remained in a deployable state at all times. CI practices help streamline development workflows, reduce integration issues, and improve collaboration among development teams.

Comments

Popular posts from this blog

Maven Create and Build Artifacts

In Maven, you can create and build artifacts using the package phase of the build lifecycle. The package phase is responsible for taking the compiled code and other project resources and packaging them into a distributable format, such as a JAR (Java Archive), WAR (Web Application Archive), or other custom formats. Here are the steps to create and build artifacts using Maven: Configure the Build Output: In your project's pom.xml file, you need to configure the output of the build. This includes specifying the type of artifact you want to create (e.g., JAR, WAR) and any additional resources to include. You do this in the <build> section of your pom.xml: <build>     <finalName>my-artifact</finalName> <!-- Name of the artifact without the extension -->     <plugins>         <!-- Plugin configurations for creating the artifact -->         <!-- For example, maven-jar-plugin or maven-war-plugin -->     </plugins> </build> Depend

Example of Maven project that interacts with a MySQL database and includes testing

Example Maven project that interacts with a MySQL database and includes testing To install Java, MySQL, Maven, and write a Java program to fetch table data, execute, and create a JAR file using Maven on Ubuntu, you can follow these steps: Step 1: Install Java You can install Java using the following commands: sudo apt update sudo apt install default-jre sudo apt install default-jdk Verify the installation by running: java -version Step 2: Install MySQL You can install MySQL using the following commands: sudo apt update sudo apt install mysql-server During the installation, you'll be prompted to set a root password for MySQL or you can set password at latter stage using following steps.  sudo mysql ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'; exit Step 3: Install Maven You can install Maven using the following commands: sudo apt update sudo apt install maven Verify the installation by running: mvn -version Step 4: Create

Experiment No. 5 Title: Applying CI/CD Principles to Web Development Using Jenkins, Git, and Local HTTP Server

  Experiment No. 5 Title: Applying CI/CD Principles to Web Development Using Jenkins, Git, and Local HTTP Server  Objective: The objective of this experiment is to set up a CI/CD pipeline for a web development project using Jenkins, Git, and webhooks, without the need for a Jenkinsfile. You will learn how to automatically build and deploy a web application to a local HTTP server whenever changes are pushed to the Git repository, using Jenkins' "Execute Shell" build step. Introduction: Continuous Integration and Continuous Deployment (CI/CD) is a critical practice in modern software development, allowing teams to automate the building, testing, and deployment of applications. This process ensures that software updates are consistently and reliably delivered to end-users, leading to improved development efficiency and product quality. In this context, this introduction sets the stage for an exploration of how to apply CI/CD principles specifically to web development using J