Skip to main content

Setting Up a Jenkins Pipeline Without Writing a Script for a GitHub Repository

Jenkins
Jenkins Pipeline Setup Guide

Jenkins Pipeline Setup Guide

This guide outlines the steps to set up a Jenkins pipeline using the graphical user interface (GUI) to connect to a GitHub repository, specifically https://github.com/SuneelG2021/spring3_project.git.

1. Launch an EC2 Instance

  1. Create an EC2 Instance

    Log in to the AWS Management Console and launch a new EC2 instance using Amazon Linux 2 or another preferred Linux distribution. Choose an instance type (e.g., t2.micro). Configure instance settings, ensuring that security groups allow traffic on ports 22 (SSH) and 8080 (Jenkins).

  2. Connect to Your EC2 Instance

    ssh -i your-key.pem ec2-user@your-ec2-public-ip

2. Install Jenkins on EC2

  1. Add Jenkins Repository

    sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
  2. Import Jenkins GPG Key

    sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
  3. Update Yum Packages

    sudo yum update -y
  4. Install Jenkins

    sudo yum install jenkins -y

3. Install Java 17 (OpenJDK)

  1. Install Java 17

    sudo yum install java-17-amazon-corretto -y
  2. Verify Java Installation

    java -version

4. Configure Java Environment Variables

  1. Set JAVA_HOME and PATH

    echo "export JAVA_HOME=$(dirname $(dirname $(readlink $(readlink $(which java)))))" | sudo tee -a /etc/profile
    echo "export PATH=$PATH:$JAVA_HOME/bin" | sudo tee -a /etc/profile
    source /etc/profile
  2. Verify JAVA_HOME

    echo $JAVA_HOME

5. Start Jenkins

  1. Start Jenkins Service

    sudo systemctl start jenkins
  2. Enable Jenkins at Boot

    sudo systemctl enable jenkins
  3. Check Jenkins Status

    sudo systemctl status jenkins

6. Adjust Security Group or Firewall Settings

  1. Allow Jenkins Port (8080)

    Open port 8080 in your security group settings in AWS:

    sudo firewall-cmd --permanent --zone=public --add-port=8080/tcp
    sudo firewall-cmd --reload

7. Access Jenkins and Complete Setup

  1. Access Jenkins

    Open a browser and navigate to:

    http://your-ec2-public-ip:8080
  2. Unlock Jenkins

    sudo cat /var/lib/jenkins/secrets/initialAdminPassword
  3. Install Suggested Plugins

    Choose "Install suggested plugins" for a quick setup.

  4. Create Admin User

    Follow prompts to create an admin account.

8. Install and Configure Maven

  1. Download Maven

    wget https://dlcdn.apache.org/maven/maven-3/3.9.9/binaries/apache-maven-3.9.9-bin.tar.gz
  2. Extract Maven

    sudo tar -xvzf apache-maven-3.9.9-bin.tar.gz -C /opt/
  3. Rename Maven Folder

    sudo mv /opt/apache-maven-3.9.9 /opt/maven
  4. Set Maven Environment Variables

    echo "export M2_HOME=/opt/maven" | sudo tee -a /etc/profile
    echo "export M2=$M2_HOME/bin" | sudo tee -a /etc/profile
    echo "export PATH=$PATH:$M2" | sudo tee -a /etc/profile
    source /etc/profile
  5. Verify Maven Installation

    mvn -version

9. Install Git

  1. Install Git

    sudo yum install git -y
  2. Verify Git Installation

    git --version

10. Configure Jenkins for Java, Maven, and Git

  1. Open Jenkins Dashboard

    Navigate to Jenkins home and log in.

  2. Navigate to Jenkins Configuration

    Go to Manage Jenkins from the sidebar.

  3. Access Global Tool Configuration

    Click on Manage Jenkins → Global Tool Configuration.

  4. Configure JDK

    Under the JDK section, click Add JDK, uncheck "Install automatically", and enter the name and path (e.g., /usr/lib/jvm/java-17-amazon-corretto).

  5. Configure Maven

    Under the Maven section, click Add Maven, enter a name (e.g., Maven 3.9.9), and provide the path (e.g., /opt/maven).

  6. Configure Git

    Under the Git section, ensure the Git executable path is set (e.g., /usr/bin/git).

11. Running a Jenkins Pipeline Without a Script

  1. Create a New Pipeline Project

    Go to the Jenkins Dashboard, click New Item, name it (e.g., MyFirstPipeline), and select Freestyle Project.

  2. Configure Source Code Management (SCM)

    In the Source Code Management section, select Git. Enter the repository URL: https://github.com/SuneelG2021/spring3_project.git. Specify the branch to build (e.g., */main).

  3. Define Build Steps Using the "Build" Section

    Add Build Steps:

    1. Invoke top-level Maven targets: Set the goal to clean install.
    2. Execute shell: Use commands like:
    3. mvn clean compile
  4. Configure Post-Build Actions

    In the Post-build Actions section, add options like Archive the artifacts or Email Notification.

  5. Save and Build the Project

    Click Save, then go to the project’s main page and click Build Now to trigger the build.

  6. Monitor and View Build Results

    Click the build number in the Build History to view Console Output for logs and check the build status.

Summary

This guide provides a comprehensive process to set up and run a Jenkins pipeline using the GUI, connected to the GitHub repository https://github.com/SuneelG2021/spring3_project.git. The configuration is completed entirely through the Jenkins interface, without the need for script writing.

Comments