التخطي إلى المحتوى الرئيسي

What is Jenkins? How to create pipeline using jenkins

 

What is Jenkins? (Simple Explanation for Students)

🔧 Jenkins is a free tool used by developers to automate tasks like:

  • Building code

  • Testing code

  • Deploying applications

💡 Think of Jenkins as a Robot Assistant:

Whenever you write code and push it to GitHub, Jenkins can:

  • Automatically test if the code works

  • Automatically build the app

  • Automatically deploy it to a server

🔁 This process is called CI/CD:

  • CI – Continuous Integration (build + test automatically)

  • CD – Continuous Deployment (deploy automatically)


🚀 Jenkins Installation: Key Steps and Important Options

🔷 Windows Installation Steps:

  1. Install Java First (JDK)
    Jenkins needs Java to run.

    • Download JDK from Oracle or OpenJDK

    • Set JAVA_HOME environment variable

    • Add Java to system PATH

  2. Download Jenkins

  3. Run Installer

    • Double-click and follow steps

    • It will install Jenkins as a Windows Service

  4. Initial Setup

    • Go to http://localhost:8080

    • Unlock Jenkins using the password in the file shown on screen

      • Path: C:\Program Files\Jenkins\secrets\initialAdminPassword

    • Install Suggested Plugins (Recommended)

    • Create Admin User

  5. Ready to Use!


🔷 Linux Installation Steps (Ubuntu/Debian Example):

  1. Install Java


    sudo apt update sudo apt install openjdk-17-jdk -y
  2. Add Jenkins Repository

    bash

    curl -fsSL https://pkg.jenkins.io/debian/jenkins.io-2023.key | sudo tee \ /usr/share/keyrings/jenkins-keyring.asc > /dev/null echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \ https://pkg.jenkins.io/debian binary/ | sudo tee \ /etc/apt/sources.list.d/jenkins.list > /dev/null
  3. Install Jenkins


    sudo apt update sudo apt install jenkins -y
  4. Start Jenkins


    sudo systemctl start jenkins sudo systemctl enable jenkins
  5. Open in Browser
    Visit http://your-server-ip:8080

    • Unlock Jenkins with password:


      sudo cat /var/lib/jenkins/secrets/initialAdminPassword
    • Install Suggested Plugins

    • Create Admin User


⭐ Most Important Options in Jenkins (For Beginners):

FeatureWhat It Does (In Simple Words)
Freestyle ProjectManually configure tasks like build/test/deploy
PipelineWrite scripts to automate build + deploy
Build TriggersRun job automatically (e.g. when code is pushed)
Source Code Management (SCM)Connect with GitHub, GitLab, Bitbucket
Post-build ActionsSend emails, deploy code, etc. after build
PluginsAdd extra features (GitHub, Docker, Slack, etc.)

Task1 create free style project to print hello world under windows machine

Step1 : Open Jenkins

Step2:   NEW ITEM

Step3    Click on Free Style Project

Step4:  Write Description if required

Step5:  Direct go into build steps

Step6:  Select Windows Batch Command if using Windows or Select Linux command

Step7: Write command  echo HelloWorld

step8: Save

Step9: Click on Build if green then pass of red then fail

Step 10: show console output


Task2:  Create Java Program and push into github using git , compile and execute this code under Jenkins using Free Style Project


Note:  Java Environment Path Must be Set in your PC check from command prompt to write java --version

Step1 : Open Jenkins

Step2:   NEW ITEM

Step3    Click on Free Style Project

Step4:  Write Description if required

Step5: Go into settings --> Manage Jenkins ---> Tools---> Configure Tools--> Set git path

Name: Default
Path    C:\Program Files\Git\bin\git.exe

Step6: Again come on Free Style Project

Step7:  go into source code management and set git public repository path

Step8 Come into Build Step Option and write following command

          echo Java Program compilation
         javac HelloWorld.java
         echo Java Program Execution
        java HelloWorld

step9: Click Build now

step 10: Click on Build and Check Console Output and show Java Code Result


Task3:  Create Python Program and push into github using git ,  execute this code under Jenkins using Free Style Project


Note:  Python Environment Path Must be Set in  System Path and Full path like this (C:\Users\Shiva-PC\AppData\Local\Programs\Python\Python313\) your PC check from command prompt to write python --version

Step1 : Open Jenkins

Step2:   NEW ITEM

Step3    Click on Free Style Project

Step4:  Write Description if required

Step5: Go into settings --> Manage Jenkins ---> Tools---> Configure Tools--> Set git path if it is not 

Name: Default
Path    C:\Program Files\Git\bin\git.exe

Step6: Again come on Free Style Project

Step7:  go into source code management and set git public repository path where python code exist

Step8 Come into Build Step Option and write following command

         python filename

step9: Click Build now

step 10: Click on Build and Check Console Output and show Java Code Result



Task4:  Build Execute by Github Webhooks


step1st:  Configure build and select Triggers GitHub hook trigger for GITScm polling
?
step2nd: go into github setting ---> Webhooks Option ---->  and try http://localhost:8080/webhooks

step3: it provide error localhost path not supported

step4:  install ngrok to map localpath to remote path

step5th install and dowload ngrok

1. Install ngrok

Download from: https://ngrok.com/download

Extract and place ngrok.exe in a known location (e.g., C:\ngrok\ngrok.exe)

2. Run ngrok to Expose Jenkins

Open Command Prompt and run:


ngrok http 8080

You’ll see output like:


Forwarding http://abc123.ngrok.io -> http://localhost:8080 Forwarding https://abc123.ngrok.io -> http://localhost:8080

✅ Copy the HTTPS URL (e.g., https://abc123.ngrok.io)

3) Manage ngrok authentication with login and authenticate token


step6:  replace ngrok url under payload url like this https://d3d61da557f0.ngrok-free.app/github-webhook/


4) choose webhooks triggers 

i choose commit and push both

5) build automatically created when you push or commit in jenkins




Task5:  Build Java Project using Maven from github (Free Style Project)


Before this task first study about maven Maven Tutorials

1)  Upload Maven Project Under github

2)  Create Free Style Project

3)  add github repsoitory and set branch

4) set windows batch command

cd MyFirstMavenProject
mvn clean package
cd target
java -cp MyFirstMavenProject-1.0-SNAPSHOT.jar com.example.App


for execution 

run this 

cd target
java -cp MyFirstMavenProject-1.0-SNAPSHOT.jar com.test.App


📌 What is a Pipeline in Jenkins?

A Jenkins Pipeline is a way to define the steps of your build process as code (written in Groovy).
Instead of clicking around in the Jenkins UI to configure a job, you put all your build steps inside a file called Jenkinsfile.

This gives you:

  • Automation (every build runs exactly the same way)

  • Version control (the pipeline code lives with your project)

  • Flexibility (build, test, deploy in sequence)


🛠 Simple Jenkins Pipeline Example

groovy

pipeline { agent any stages { stage('Hello') { steps { echo 'Hello from Jenkins Pipeline!' } } } }

 Another Jenkins Pipeline Example

pipeline { agent any stages { stage('BUILD') { steps { echo 'Hello This is for Build' } } stage('TEST') { steps { echo 'Hello This is for Test!' } } stage('DEPLOY') { steps { echo 'Hello This is Deploy !' } } } }

Task6:  Build Java Project using Maven from github (Pipeline Style Project)

1)  create project using maven
2)  push into github repository
3) create jenkinspipelinebuild
4) write this pipleine script

pipeline {
    agent any

    tools {
        maven 'Maven_3.9.6'  // name from Global Tool Config
        jdk 'JDK17'          // name from Global Tool Config
    }

    stages {
        stage('Checkout') {
            steps {
                git branch: 'main', url: 'https://github.com/shivaconceptsolution/MyFirstMavenProject.git'
            }
        }

        stage('Build') {
            steps {
                bat 'mvn clean package'
            }
        }

        stage('Run Application') {
            steps {
                bat 'java -cp target/MyFirstMavenProject-1.0-SNAPSHOT.jar com.test.App'
            }
        }
    }
}


تعليقات

المشاركات الشائعة من هذه المدونة

DSA in C# | Data Structure and Algorithm using C#

  DSA in C# |  Data Structure and Algorithm using C#: Lecture 1: Introduction to Data Structures and Algorithms (1 Hour) 1.1 What are Data Structures? Data Structures are ways to store and organize data so it can be used efficiently. Think of data structures as containers that hold data in a specific format. Types of Data Structures: Primitive Data Structures : These are basic structures built into the language. Example: int , float , char , bool in C#. Example : csharp int age = 25;  // 'age' stores an integer value. bool isStudent = true;  // 'isStudent' stores a boolean value. Non-Primitive Data Structures : These are more complex and are built using primitive types. They are divided into: Linear : Arrays, Lists, Queues, Stacks (data is arranged in a sequence). Non-Linear : Trees, Graphs (data is connected in more complex ways). Example : // Array is a simple linear data structure int[] number...

JSP Page design using Internal CSS

  JSP is used to design the user interface of an application, CSS is used to provide set of properties. Jsp provide proper page template to create user interface of dynamic web application. We can write CSS using three different ways 1)  inline CSS:-   we will write CSS tag under HTML elements <div style="width:200px; height:100px; background-color:green;"></div> 2)  Internal CSS:-  we will write CSS under <style> block. <style type="text/css"> #abc { width:200px;  height:100px;  background-color:green; } </style> <div id="abc"></div> 3) External CSS:-  we will write CSS to create a separate file and link it into HTML Web pages. create a separate file and named it style.css #abc { width:200px;  height:100px;  background-color:green; } go into Jsp page and link style.css <link href="style.css"  type="text/css" rel="stylesheet"   /> <div id="abc"> </div> Exam...

Top 50 Most Asked MERN Stack Interview Questions and Answers for 2025

 Top 50 Most Asked MERN Stack Interview Questions and Answers for 2025 Now a days most of the IT Company asked NODE JS Question mostly in interview. I am creating this article to provide help to all MERN Stack developer , who is in doubt that which type of question can be asked in MERN Stack  then they can learn from this article. I am Shiva Gautam,  I have 15 Years of experience in Multiple IT Technology, I am Founder of Shiva Concept Solution Best Programming Institute with 100% Job placement guarantee. for more information visit  Shiva Concept Solution 1. What is the MERN Stack? Answer : MERN Stack is a full-stack JavaScript framework using MongoDB (database), Express.js (backend framework), React (frontend library), and Node.js (server runtime). It’s popular for building fast, scalable web apps with one language—JavaScript. 2. What is MongoDB, and why use it in MERN? Answer : MongoDB is a NoSQL database that stores data in flexible, JSON-like documents. It...