Showing posts with label Jenkins. Show all posts
Showing posts with label Jenkins. Show all posts

Friday, 5 September 2025

How to build Java project using Jenkins and create war files

 

After integration of Maven, Java and Git in Jenkins create new Project in Jenkins with below details:-


In my case my Java code is save in below git repo:-





Then Apply and Save and click on build now:-



Then build will be start after its done webapp.war files will be save in below path:-



Thursday, 4 September 2025

How to integrate Maven with Jenkins to build Java Project

Step 1:- Download Maven from official sites:-  

https://maven.apache.org/download.cgi


[root@jenkins-server ~]# pwd

/root

[root@jenkins-server ~]# cd /opt/

[root@jenkins-server opt]# ls

[root@jenkins-server opt]# ls

[root@jenkins-server opt]# wget https://dlcdn.apache.org/maven/maven-3/3.9.11/binaries/apache-maven-3.9.11-bin.tar.gz

--2025-09-05 04:46:31--  https://dlcdn.apache.org/maven/maven-3/3.9.11/binaries/apache-maven-3.9.11-bin.tar.gz

Resolving dlcdn.apache.org (dlcdn.apache.org)... 151.101.2.132, 2a04:4e42::644

Connecting to dlcdn.apache.org (dlcdn.apache.org)|151.101.2.132|:443... connected.

HTTP request sent, awaiting response... 200 OK

Length: 9160848 (8.7M) [application/x-gzip]

Saving to: ‘apache-maven-3.9.11-bin.tar.gz’


apache-maven-3.9.11-bin.tar.gz            100%[===================================================================================>]   8.74M  --.-KB/s    in 0.08s


2025-09-05 04:46:32 (113 MB/s) - ‘apache-maven-3.9.11-bin.tar.gz’ saved [9160848/9160848]


[root@jenkins-server opt]# ls

apache-maven-3.9.11-bin.tar.gz


Step 2:- Once downloaded the untar it.


[root@jenkins-server opt]# tar -xvzf apache-maven-3.9.11-bin.tar.gz

apache-maven-3.9.11/README.txt

apache-maven-3.9.11/LICENSE

apache-maven-3.9.11/NOTICE

apache-maven-3.9.11/lib/

apache-maven-3.9.11/lib/aopalliance.license

apache-maven-3.9.11/lib/asm.license

 


Step 3 :- Rename the folder name



[root@jenkins-server opt]# ls

apache-maven-3.9.11  apache-maven-3.9.11-bin.tar.gz

[root@jenkins-server opt]# mv apache-maven-3.9.11 maven

[root@jenkins-server opt]# ls

apache-maven-3.9.11-bin.tar.gz  maven

[root@jenkins-server opt]# cd maven/

[root@jenkins-server maven]# ls

LICENSE  NOTICE  README.txt  bin  boot  conf  lib

[root@jenkins-server maven]# cd bin/

[root@jenkins-server bin]# ls

m2.conf  mvn  mvn.cmd  mvnDebug  mvnDebug.cmd  mvnyjp


Run the manven command to check:-


[root@jenkins-server bin]# ./mvn -v

Apache Maven 3.9.11 (3e54c93a704957b63ee3494413a2b544fd3d825b)

Maven home: /opt/maven

Java version: 21.0.8, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-21-openjdk

Default locale: en, platform encoding: UTF-8

OS name: "linux", version: "6.12.0-55.25.1.el10_0.x86_64", arch: "amd64", family: "unix"



Step 4:- Now set environment variable to run from anywhere 


[root@jenkins-server bin]# cd ~

[root@jenkins-server ~]# ls

'='

[root@jenkins-server ~]# ls -a

 .   ..   .bash_history   .bash_logout   .bash_profile   .bashrc   .cshrc   .ssh   .tcshrc   .wget-hsts  '='

[root@jenkins-server ~]# vi .bash_profile

[root@jenkins-server ~]# cat .bash_profile

# .bash_profile


# Get the aliases and functions

if [ -f ~/.bashrc ]; then

        . ~/.bashrc

fi

M2_HOME=/opt/maven

M2=/opt/maven/bin

JAVA_HOME=/usr/lib/jvm/java-17-openjdk-17.0.16.0.8-2.el9.x86_64

# User specific environment and startup programs


PATH=$PATH:$HOME/bin:$JAVA_HOME:$M2_HOME:$M2


export PATH

[root@jenkins-server ~]# source .bash_profile

[root@jenkins-server ~]# echo $PATH

/root/.local/bin:/root/bin:/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/lib/jvm/java-17-openjdk-17.0.16.0.8-2.el9.x86_64:/opt/maven:/opt/maven/bin

[root@jenkins-server ~]# mvn -v

Apache Maven 3.9.11 (3e54c93a704957b63ee3494413a2b544fd3d825b)

Maven home: /opt/maven

Java version: 21.0.8, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-21-openjdk

Default locale: en, platform encoding: UTF-8

OS name: "linux", version: "6.12.0-55.25.1.el10_0.x86_64", arch: "amd64", family: "unix"

[root@jenkins-server ~]#



To find Java path run below command:-

[root@jenkins-server ~]# find / -name jvm
/usr/lib/jvm
/usr/share/jvm
/etc/jvm
[root@jenkins-server ~]# cd /usr/lib/jvm
[root@jenkins-server jvm]# ls
java                                      java-21-openjdk  jre-17-openjdk                           jre-openjdk
java-17                                   java-openjdk     jre-17-openjdk-17.0.16.0.8-2.el9.x86_64
java-17-openjdk                           jre              jre-21
java-17-openjdk-17.0.16.0.8-2.el9.x86_64  jre-17           jre-21-openjdk
[root@jenkins-server jvm]# ls -ltrh
total 0
lrwxrwxrwx. 1 root root 40 Aug 18 20:05 jre-17-openjdk-17.0.16.0.8-2.el9.x86_64 -> java-17-openjdk-17.0.16.0.8-2.el9.x86_64
drwxr-xr-x. 7 root root 97 Sep  3 07:27 java-17-openjdk-17.0.16.0.8-2.el9.x86_64
lrwxrwxrwx. 1 root root 21 Sep  3 07:27 jre -> /etc/alternatives/jre
lrwxrwxrwx. 1 root root 29 Sep  3 07:27 jre-openjdk -> /etc/alternatives/jre_openjdk
lrwxrwxrwx. 1 root root 24 Sep  3 07:27 jre-17 -> /etc/alternatives/jre_17
lrwxrwxrwx. 1 root root 32 Sep  3 07:27 jre-17-openjdk -> /etc/alternatives/jre_17_openjdk
lrwxrwxrwx. 1 root root 26 Sep  3 07:27 java -> /etc/alternatives/java_sdk
lrwxrwxrwx. 1 root root 34 Sep  3 07:27 java-openjdk -> /etc/alternatives/java_sdk_openjdk
lrwxrwxrwx. 1 root root 29 Sep  3 07:27 java-17 -> /etc/alternatives/java_sdk_17
lrwxrwxrwx. 1 root root 37 Sep  3 07:27 java-17-openjdk -> /etc/alternatives/java_sdk_17_openjdk
drwxr-xr-x. 5 root root 68 Sep  3 10:12 java-21-openjdk
lrwxrwxrwx. 1 root root 24 Sep  3 10:12 jre-21 -> /etc/alternatives/jre_21
lrwxrwxrwx. 1 root root 32 Sep  3 10:12 jre-21-openjdk -> /etc/alternatives/jre_21_openjdk





Now install Maven plugins in Jenkins and configure path .

Also configure path of git and Java in Jenkins






If you have multiple java install and to select java 17 use below command:-




Wednesday, 3 September 2025

How to install Jenkins on Redhat EC2 Server

 Step 1:  Download below repo


[root@ip-172-31-18-18 ~]# sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo

--2025-09-03 10:08:33--  https://pkg.jenkins.io/redhat-stable/jenkins.repo

Resolving pkg.jenkins.io (pkg.jenkins.io)... 146.75.38.133, 2a04:4e42:56::645

Connecting to pkg.jenkins.io (pkg.jenkins.io)|146.75.38.133|:443... connected.

HTTP request sent, awaiting response... 200 OK

Length: 85

Saving to: ‘/etc/yum.repos.d/jenkins.repo’


/etc/yum.repos.d/jenkins.repo             100%[===================================================================================>]      85  --.-KB/s    in 0s


2025-09-03 10:08:33 (2.71 MB/s) - ‘/etc/yum.repos.d/jenkins.repo’ saved [85/85]


===================================================

Step 2:  Download key

[root@ip-172-31-18-18 ~]# sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key


==========================================
Step 3:-  Install java

[root@ip-172-31-18-18 ~]# sudo yum install fontconfig java-21-openjdk
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use "rhc" or "subscription-manager" to register.

Last metadata expiration check: 0:03:37 ago on Wed Sep  3 10:08:57 2025.
Package fontconfig-2.15.0-7.el10.x86_64 is already installed.

============================================
Step 4:- Install Jenkin now


[root@ip-172-31-18-18 ~]# sudo yum install jenkins
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use "rhc" or "subscription-manager" to register.

Last metadata expiration check: 0:03:58 ago on Wed Sep  3 10:08:57 2025.

============================================================
Step 5:-  Start the Jenkins

[root@ip-172-31-18-18 ~]# sudo systemctl daemon-reload
[root@ip-172-31-18-18 ~]# sudo systemctl enable jenkins
Created symlink '/etc/systemd/system/multi-user.target.wants/jenkins.service' → '/usr/lib/systemd/system/jenkins.service'.
[root@ip-172-31-18-18 ~]# sudo systemctl start jenkins
[root@ip-172-31-18-18 ~]# sudo systemctl status jenkins
● jenkins.service - Jenkins Continuous Integration Server
     Loaded: loaded (/usr/lib/systemd/system/jenkins.service; enabled; preset: disabled)
     Active: active (running) since Wed 2025-09-03 10:13:52 UTC; 19s ago
 Invocation: 7cec58f4a86b4ad98baa29275db3c9f4
   Main PID: 14143 (java)
      Tasks: 42 (limit: 5687)
     Memory: 452.6M (peak: 462.1M)
        CPU: 14.054s
     CGroup: /system.slice/jenkins.service

===================================================
Step 6:-  Now access the Jenkings by using public ip and port 8080

http://52.90.54.118:8080/

/var/lib/jenkins/secrets/initialAdminPassword





Monday, 11 March 2019

How to Install Jenkins by Raj Gupta


Prerequisites

  1. EC2 Instance
    • With Internet Access
    • Security Group with Port 8080 open for internet
  2. Java 11 should be installed

Install Jenkins

You can install jenkins using the rpm or by setting up the repo. We will set up the repo so that we can update it easily in the future.

  1. Get the latest version of jenkins from https://pkg.jenkins.io/redhat-stable/ and install

    sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
    sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
    amazon-linux-extras install epel 
    amazon-linux-extras install java-openjdk11  
    
    #on RedHat/CentOs 
    #yum install epel-release # repository that provides 'daemonize'
    #yum install java-11-openjdk-devel
    #yum install jenkins

    Start Jenkins

    # Start jenkins service
    service jenkins start
    
    # Setup Jenkins to start at boot,
    chkconfig jenkins on

    Accessing Jenkins

    By default jenkins runs at port 8080, You can access jenkins at

    http://YOUR-SERVER-PUBLIC-IP:8080

Configure Jenkins

  • The default Username is admin
  • Grab the default password
  • Password Location:/var/lib/jenkins/secrets/initialAdminPassword
  • Skip Plugin Installation; We can do it later
  • Change admin password
    • Admin > Configure > Password
  • Configure java path
    • Manage Jenkins > Global Tool Configuration > JDK
  • Create another admin user id

Test Jenkins Jobs

  1. Create “new item”
  2. Enter an item name – My-First-Project
    • Chose Freestyle project
  3. Under the Build section Execute shell: echo "Welcome to Jenkins Demo"
  4. Save your job
  5. Build job
  6. Check "console output"