Jenkins part9
Class 29th Jenkins May 21st
Jenkins part is over final Project below
->Why is the deployment and why it is ?
->Deployment flow
->Environment Setup
->What precautions should we take before deployment?
->Jenkins End-to-End Project: Practical
We will take one Java Project from Git, deploy into the application (tomcat) container
->Why is the deployment and why it is ?
Deployment : Deployment refers to the process of installing a web application on a server.
(simple what every we build .jar/.war application file simple copying to application servers called deployment,but now days no one not do direct copy, we do deployment with tools)
Why Deployment:
the main Reasons of the deployment are:
.Installation of a web-application on web-server.
.Adding new features to the application and fixing bugs.
.Enhancing existing features and improving performance.
.Breakdown large applications into microservices for better scalability and maintainability.
Practical
Deployment Flow
Step1:
Need to create two Instances Jenkins , tomcat and nexus
Jekins Server
[root@ip-10-0-0-81 ~]# yum install -y java-17-amazon-corretto-devel git [root@ip-10-0-0-81 ~]# sudo wget -O /etc/yum.repos.d/jenkins.repo \ https://pkg.jenkins.io/redhat-stable/jenkins.repo
[root@ip-10-0-0-81 ~]# sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
[root@ip-10-0-0-81 ~]# sudo yum install jenkins
click y
[root@ip-10-0-0-81 ~]# systemctl start jenkins
Connect jenkins public ip http://54.195.135.216:8080/
[root@ip-10-0-0-81 jenkins]# cat /var/lib/jenkins/secrets/initialAdminPassword
dd9c30c4b0b2451098c09233c9d60ab9
click initiated create user admin/ required password
Tomcat server :tomcat-users.xml using for some roles to add, '56d' d means delete
Take public ip for the server
tomcat.sh script
yum install java-17-amazon-corretto -y
wget https://dlcdn.apache.org/tomcat/tomcat-11/v11.0.7/bin/apache-tomcat-11.0.7.tar.gz
(This is not final one you main url check latest version and download)
tar -zxvf apache-tomcat-11.0.7.tar.gz
sed -i '56 a\<role rolename="manager-gui"/>' apache-tomcat-11.0.7/conf/tomcat-users.xml
sed -i '57 a\<role rolename="manager-script"/>' apache-tomcat-11.0.7/conf/tomcat-users.xml
sed -i '58 a\<user username="tomcat" password="ccit123" roles="manager-gui, manager-script"/>' apache-tomcat-11.0.7/conf/tomcat-users.xml
sed -i '59 a\</tomcat-users>' apache-tomcat-11.0.7/conf/tomcat-users.xml
sed -i '56d' apache-tomcat-11.0.7/conf/tomcat-users.xml
sed -i '21d' apache-tomcat-11.0.7/webapps/manager/META-INF/context.xml
sed -i '22d' apache-tomcat-11.0.7/webapps/manager/META-INF/context.xml
sh apache-tomcat-11.0.7/bin/startup.sh
[ec2-user@ip-10-0-1-93 ~]$ sudo -i
[root@ip-10-0-1-93 ~]# vi tomcat.sh
[root@ip-10-0-1-93 ~]# sh tomcat.sh
Tomcat started.
[root@ip-10-0-1-93 ~]#
Step2: Click Manager app after open the below url ,Login with password ,mentioned above script
http://3.255.200.138:8080/
Below is the web application manager ,for this manager container ,we will hosting our application
Step3:Git project simple html webpage ,We plan deploy this into tomcat
https://github.com/cloudcomputingintelugu/ccitwebsite-java
We need create one job in Jenkis Click ok
Jobname: ccitpipe-prj
Step4: Prior we need configure maven given any name ccit-mvn click save
Dashboard> Manage Jenkins > Tools
For Containerization we need add one plugin
Dashboard> Manage Jenkins > Plugins >Available plugins enter text Deploy to Container click install (this artifact upload)
Pipeline stage view click install (This for view good )
Nexus Artifact uploader click install(if required we can choose s3 artifact uploader)
Step5:add credentials
Dashboard> Manage Jenkins >Credentials Click system >Click Global credentials (unrestricted)
and Click add credentials
Click Create, We can another way also while pipe scripts add there also we can supply the user and password,using pipline syntax script
now Java tomcat server not supported for .jar file to deploy , only support .war or .ear file only
Or
Another way to pipeline syntax script
Simple Step : Deployment war/ear to container
Deploy War/Ear files :target/*war
Context patch :ccitwebsite (give any name)
Contaner : Tomcat :take latest version
Credential: tomat/ccit123 (which is you given script)
Tomcat URL : http://54.185.135.216:8080/ (tomcat url public ip)
Step6: job which added early yar
Jobname: ccitpipe-prj
Definition add below script and build
pipeline {
agent any
tools
{
maven 'ccit-mvn'
}
stages {
stage('git') {
steps {
git 'https://github.com/cloudcomputingintelugu/ccitwebsite-java.git'
}
}
stage('build') {
steps {
sh 'mvn clean package'
}
}
}
}
Step7: build success
After build success ,below you jenkins server this you artifacts myweb-0.0.1.war this you need to deploy(upload) in tomcat
[root@ip-10-0-0-81 target]# pwd
/var/lib/jenkins/workspace/ccitpipe-prj/target
[root@ip-10-0-0-81 target]# ls -lrt
total 4
drwxr-xr-x 4 jenkins jenkins 89 May 22 19:25 myweb-0.0.1
drwxr-xr-x 2 jenkins jenkins 28 May 22 19:25 maven-archiver
-rw-r--r-- 1 jenkins jenkins 4069 May 22 19:25 myweb-0.0.1.war
Click Job Pipline Generate syntax script text copy add this into out job pipline stage script
deploy adapters: [tomcat9(alternativeDeploymentContext: '', credentialsId: '732bd861-4be4-49a0-aba2-04a19991b198', path: '', url: 'http://3.255.200.138:8080/')], contextPath: 'ccitwebsite', war: 'target/*.war'
Step8: Click save and build
pipeline {
agent any
tools
{
maven 'ccit-mvn'
}
stages {
stage('git') {
steps {
git 'https://github.com/cloudcomputingintelugu/ccitwebsite-java.git'
}
}
stage('build') {
steps {
sh 'mvn clean package'
}
}
stage('tomcat') {
steps {
deploy adapters: [tomcat9(alternativeDeploymentContext: '', credentialsId: '732bd861-4be4-49a0-aba2-04a19991b198', path: '', url: 'http://3.255.200.138:8080/')], contextPath: 'ccitwebsite', war: 'target/*.war'
}
}
}
}
Step9: after build tomcat add and build success
Step10: See below screen shot which we have given name ccitwebsite came to tomcat site
We can able host multiple website also using this
Step11:Website hosted
Above sofar done we have placed through build artifacats moved from maven to tomcat
Now we plan to go with Nexus move from artifacts nexus to tomcat prior stop this webhost
Now page is open line this ,after stopped
HTTP Status 404 – Not Found
Type Status Report
Message The requested resource [/ccitwebsite/] is not available
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Apache Tomcat/11.0.7
Nexus
https protocol need run our website need to certificate ssl aws ssl certificate is free
We need purchase domain or Route 53
The service in AWS Console "Certificate manager "
>click List Certificate
Note :- While start nexus with micro amazon Linux facing below issue ,so Nexus minimum small Linux required it is chargeable
Launch a t2.micro
EC2 with Amazon Linux 2 Failed
For Nexus minimum Linux small, with micro free tier facing issue [root@ip-10-0-1-241 bin]# ./nexus run
WARNING: ************************************************************
WARNING: Detected execution as "root" user. This is NOT recommended!
WARNING: ************************************************************
OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x000000078f550000, 1890254848, 0) failed; error='Not enough space' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 1890254848 bytes. Error detail: committing reserved memory.
# An error report file with more information is saved as:
# /opt/nexus/nexus-3.80.0-06/hs_err_pid7284.log
[root@ip-10-0-1-241 bin]# Connection to 3.249.223.100 closed by remote host.
Connection to 3.249.223.100 closed
Step1: Nexus Launching
Amazon linux
Instance type:t2.medium
Storge changed 20 GB
Step2:
Java Installation
[ec2-user@ip-10-0-0-244 ~]$ sudo -i
[root@ip-10-0-0-244 ~]# sudo yum install -y java-17-amazon-corretto-devel
Step3: Need Install Nexus in linux,for software always go with prior url
https://help.sonatype.com/en/download.html
and Download latest version above url take you latest Unix Nexus repository right click url save copy link address
[root@ip-10-0-0-244 ~]#wget https://download.sonatype.com/nexus/3/nexus-3.80.0-06-linux-x86_64.tar.gz
[root@ip-10-0-0-244 ~]#tar -zxvf nexus-3.80.0-06-linux-x86_64.tar.gz
Step4:User creation nexus
[root@ip-10-0-0-244 ~]# useradd nexus
[root@ip-10-0-0-244 ~]# ls -lrt
total 416436
drwxr-xr-x 3 root root 20 May 2 20:55 sonatype-work
-rw-r--r-- 1 root root 426428974 May 6 16:15 nexus-3.80.0-06-linux-x86_64.tar.gz
drwxr-xr-x 6 root root 94 May 23 10:23 nexus-3.80.0-06
[root@ip-10-0-0-244 ~]# chown nexus:nexus nexus-3.80.0-06 sonatype-work
[root@ip-10-0-0-244 ~]# ls -lrt
total 416436
drwxr-xr-x 3 nexus nexus 20 May 2 20:55 sonatype-work
-rw-r--r-- 1 root root 426428974 May 6 16:15 nexus-3.80.0-06-linux-x86_64.tar.gz
drwxr-xr-x 6 nexus nexus 94 May 23 10:23 nexus-3.80.0-06
Step5: In the nexus file need to change line number 27 run_as_user='' to run_as_user='nexus'
[root@ip-10-0-0-244 bin]# vi nexus
:set number
(set number command for vi script number display)
26 # user to execute as; optional but recommended to set
27 run_as_user='nexus'
[root@ip-10-0-0-244 opt]# mkdir -p /opt/sonatype-work/nexus3
Getting some permission issue
[root@ip-10-0-0-244 bin]# ./nexus start
-bash: /root/nexus-3.80.0-06/bin/nexus: Permission denied
[root@ip-10-0-0-244 bin]# mkdir -p /opt/nexus
[root@ip-10-0-0-244 bin]# mv /root/nexus-3.80.0-06 /opt/nexus/
[root@ip-10-0-0-244 bin]# cd /opt/nexus/nexus-3.80.0-06/bin
[root@ip-10-0-0-244 bin]# ./nexus start
Last login: Fri May 23 10:26:39 UTC 2025 on pts/0
mkdir: cannot create directory ‘/opt/nexus/nexus-3.80.0-06/../sonatype-work’: Permission denied
realpath: ‘/opt/nexus/nexus-3.80.0-06/../sonatype-work/nexus3’: No such file or directory
mkdir: cannot create directory ‘/log’: Permission denied
Starting nexus
/opt/nexus/nexus-3.80.0-06/bin/nexus: line 175: /nexus.pid: Permission denied
[root@ip-10-0-0-244 bin]# cd /opt/nexus/nexus-3.80.0-06
[root@ip-10-0-0-244 nexus-3.80.0-06]# ls
bin deploy etc jdk NOTICE.txt OSS-LICENSE.txt
[root@ip-10-0-0-244 opt]# chown -R nexus:nexus /opt/sonatype-work -R
[root@ip-10-0-0-244 opt]# sudo passwd nexus
Changing password for user nexus.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@ip-10-0-0-244 opt]# sudo chown -R nexus:nexus /opt/nexus
[root@ip-10-0-0-244 opt]# export NEXUS_DATA=/opt/nexus/sonatype-work
[root@ip-10-0-0-244 opt]# sudo su - nexus
Last login: Fri May 23 10:33:20 UTC 2025 on pts/0
[nexus@ip-10-0-0-244 ~]$ /opt/nexus/nexus-3.80.0-06/bin/nexus start
Starting nexus
[nexus@ip-10-0-0-244 ~]$ /opt/nexus/nexus-3.80.0-06/bin/nexus stop
Shutting down nexus
Stopping nexus running with pid 9738
Step6: Take the public Ip for the nexus instance default port 8081
Login with user admin password
[nexus@ip-10-0-0-244 opt]$ cat /opt/nexus/sonatype-work/nexus3/admin.password
88d25272-af46-45b7-adf9-ae42f115d1da
Click Sign in Next > Choose Radio Disable anonymous access >Click next
Step7: Click repository ,select maven2(hosted)
Step8: Give any repo name in nexus repository and select deployment policy Allow redeploy
Step9:Created one repository in nexus successfully Step10: Jenkins pipline job, need to added nexus script step,with that take help of pipeline syntax script ,Select below options, Process url past nexus url with out http 10.1
10.2 add admin credential of nexus Groupid,version get it from the Git Pom.xml,Repository ccitrepo nexus repo name

10.3: Artifact id ,type of file war , war file location in jenkins server ,click generate pipline script
10.4 Git Project below pom.xml
Step11: ccitpipelinejob >Configuration > add below script ,nexus script you need replace with your pipline syntax script
pipeline {
agent any
tools
{
maven 'ccit-mvn'
}
stages {
stage('git') {
steps {
git 'https://github.com/cloudcomputingintelugu/ccitwebsite-java.git'
}
}
stage('build') {
steps {
sh 'mvn clean package'
}
}
stage('nexus') {
steps {
deploy adapters: [tomcat9(alternativeDeploymentContext: '', credentialsId: '8cf5a8fa-814b-4f44-9834-510bd831b76e', path: '', url: 'http://3.250.85.185:8080/')], contextPath: 'ccitwebsite', war: 'target/*.war'
}
}
stage('tomcat') {
steps {
deploy adapters: [tomcat9(alternativeDeploymentContext: '', credentialsId: '8cf5a8fa-814b-4f44-9834-510bd831b76e', path: '', url: 'http://3.250.85.185:8080/')], contextPath: 'ccitwebsite1', war: 'target/*.war' }
}
}
}
Here is the screen shot script need add click save the job
Step 12. Save job and Build it is completed Successfully, with stage view you see nexus added file transfer to tomcatStep13: See here below screen shot , nexus repo .war file deployed successfully, in the nexus pipeline script, for difference first example maven to tomcat, second example maven ->nexus->tomcat hostname change "ccitwebsite1"Step14: See below Application path newly came /ccitwebsite1Step2: After click, web host page opened successfully.--Thanks
Using S3 Bucket instead of Nexus High-end server paid not free-tier
Step1: Using I am Service create one user jenkins-s3-user, Add policy "AmazonS3FullAccess" and create
Step2:Add Security key for the user ,download for better
Step3: Source :Jenkin Server already Java,Git and Jenkis installed started Jenkin service
Create one simple S3 bucket in aws >
Name Bucket :ccitnexusbucket
Bucket type :General Purpose
Object ownership : ASLs disabled(recommended) default
Created one bucket
Jenkins
Dashboard → Manage Jenkins →plugins >Available plugins
S3 publisher, (optional Stage viewer)
Step5: After Added Plugins , Need to attach Iam user( i.e jenkins-s3-user Download Accesskey ) to S3 profile below navigation Jenkins Dashboard → Manage Jenkins >System
Profile :aws-profile (given name)
Access key:XXXXXX(which you have download IAM User )
Secret key:XXXXX
Click Save
Step6: For Generate Pipeline script use job Pipeline syntax Sample step: General Build Step
Build Step :Publish Artifacts to S3 Bucket
S3 Profile : aws-profile (it came automatically which you have add profile above step)
Source :target/*.war (Jenkins sever where you artifacts)
Destination bucket: ccitnexusbucket
Bucket Region : eu-west-1 (where you bucket region)
Click Generate pipeline script ,copy the test Step7:Genkins > Create one job pipeline job Click save and Build pipeline {
agent any
tools{
maven 'ccit-mvn'
}
stages {
stage('git') {
steps {
git 'https://github.com/cloudcomputingintelugu/ccitwebsite-java.git'
}
}
stage('build') {
steps {
sh 'mvn clean package'
}
}
stage('Upload to S3') {
steps {
s3Upload consoleLogLevel: 'INFO', dontSetBuildResultOnFailure: false, dontWaitForConcurrentBuildCompletion: false, entries: [[bucket: 'ccitnexusbucket', excludedFile: '', flatten: false, gzipFiles: false, keepForever: false, managedArtifacts: false, noUploadOnFailure: false, selectedRegion: 'eu-west-1', showDirectlyInBrowser: false, sourceFile: 'target/*.war', storageClass: 'STANDARD', uploadFromSlave: false, useServerSideEncryption: false]], pluginFailureResultConstraint: 'FAILURE', profileName: 'aws-profile', userMetadata: []
}
}
}
}
Step8: Build success, See below S3 upload also successStep9:See below s3 ccitnexusbucket artifacts uploaded successfully.
Create one instance >tomcat Server > execute below script root
tomcat.sh script
yum install java-17-amazon-corretto -y
wget https://dlcdn.apache.org/tomcat/tomcat-11/v11.0.7/bin/apache-tomcat-11.0.7.tar.gz
(This is not final one you main url check latest version and download)
tar -zxvf apache-tomcat-11.0.7.tar.gz
sed -i '56 a\<role rolename="manager-gui"/>' apache-tomcat-11.0.7/conf/tomcat-users.xml
sed -i '57 a\<role rolename="manager-script"/>' apache-tomcat-11.0.7/conf/tomcat-users.xml
sed -i '58 a\<user username="tomcat" password="ccit123" roles="manager-gui, manager-script"/>' apache-tomcat-11.0.7/conf/tomcat-users.xml
sed -i '59 a\</tomcat-users>' apache-tomcat-11.0.7/conf/tomcat-users.xml
sed -i '56d' apache-tomcat-11.0.7/conf/tomcat-users.xml
sed -i '21d' apache-tomcat-11.0.7/webapps/manager/META-INF/context.xml
sed -i '22d' apache-tomcat-11.0.7/webapps/manager/META-INF/context.xml
sh apache-tomcat-11.0.7/bin/startup.sh
Step11: login tomcate public ip
Another way to pipeline syntax script
Simple Step : Deployment war/ear to container
Deploy War/Ear files :target/*war
Context patch :ccitwebsite (give any name)
Contaner : Tomcat :take latest version
Credential: tomat/ccit123 (which is you given script)
Tomcat URL : http://18.201.159.187:8080/ (tomcat url public ip)
deploy adapters: [tomcat9(alternativeDeploymentContext: '', credentialsId: 'ff93c1a6-d180-4658-a61f-e43c790065a5', path: '', url: 'http://18.201.159.187:8080/')], contextPath: 'ccitwebsite', war: 'target/*.war'
stage('tomcat') {
steps {
deploy adapters: [tomcat9(alternativeDeploymentContext: '', credentialsId: 'ff93c1a6-d180-4658-a61f-e43c790065a5', path: '', url: 'http://18.201.159.187:8080/')], contextPath: 'ccitwebsite', war: 'target/*.war'
}
}
Full script : Step7 add above script
Step13: Build Completed Successfully
Step14: Webpage hosted in tomcat Step15: Web hostname open successfully --Thanks
No comments:
Post a Comment