deploy web server through pipeline
Declarative Pipeline Deployment
Here, we are doing deployment in single server i.e.., Jenkins + Tomcat setups in single server
1. First Launch Jenkins Server and setup the jenkins
2. Create the pipeline
3. And write the pipeline script
S
IN
Step-1: Code
First create the jenkins setup, Create a Pipeline job
NK
For github code, fork my github project. Below is my project url and username is “chiksand”
JE
LA
KA
Go to workspace → myproject → src → main → webapp → index.jsp
In this index.jsp file , we are having source code. This code will done by developers
Fetching Code from GIT → First, Install git in server
K
Pipeline Syntax: If my code is in another branch, I want to get that code means ,we use pipeline syntax
HI
for git
PC
Now, Go to pipeline script → For git syntax → Click on pipeline syntax and inside repo URL paste
your github repo code link like in the given below
EE
ND
SA
Click on Generate Pipeline Script
Copy that script → git 'https://github.com/chiksand/one.git'
And write inside the stages like given below
S
IN
NK
JE
LA
click on save and build and check the changes in jenkins path inside our server, we have repositories
KA
Step-2: Build
K
Here, we have to do maven setup
First install maven dependency i.e., java → yum install java-1.8.0-openjdk -y
HI
So, here java version are not override. In linux, this is the benefit we had. We can maintain
multiple versions
PC
So, present you want to check, which java version is running means we have command
update-alternatives --config java
Through this command we are getting java versions “* +” symbol was there in java version
EE
that means present that java is running
If you want to change java version, you can enter the number
If you want current version just click ENTER
ND
Second, install maven → yum install maven -y
Check the version → mvn -v
SA
make sure you have to get like above image means from server side you are clear
Go to Pipeline job and above code continuation write the below code
S
After save and build you will get a war file
IN
Step-3: Deploy
NK
For Deployment purpose , we have to do Tomcat setup in same server
1. Go to browser → dlcdn.apache.org → tomcat/ → tomcat9/ → v9.0.78/ → bin → apache-tomcat-
JE
9.0.78.tar.gz
2. Go to terminal → wget apache-tomcat-9.0.78.tar.gz
3. gunzip the file → tar -zxvf fileName → ll → apache-tomcat-9.0.78/
4.
5.
LA
Start the tomcat, Go to → cd apache-tomcat-9.0.78/ → cd bin/ → ./ startup.sh
Default port number for tomcat is 8080
KA
But that port number is already used by Jenkins. So, we have to change the tomcat port number
Go to apache → conf → vi server.xml → in 69th line change the port number from 8080 to any
K
number. Here, I written 8081 port number
HI
PC
EE
Open tomcat in browser i.e. publicIP:8081. and select Manager App you will get below image
ND
SA
Now above image is displaying tomcat is not access for us. So, read the description
1. Edit the manager’s folder in context.xml file
a. cd apache-tomcat-9.0.78/ → webapps → manager → META-INF → vi context.xml
i. Here, delete 21, 22 lines i.e.., <valve ..... > save and exit
2. Again try to access tomcat browser, it’s asking credentials
a. cd apache-tomcat-9.0.78/ → conf → vi tomcat-users.xml
i. Here, we need to add the credentials, we have this description in apache
ii. we have to add 2 roles i.e., manager-gui, manager-script
S
IN
NK
Perform same above steps and you can give any username and password
b. So, here we changed the configuration file, we need to restart
JE
i. Go to cd apache-tomcat-9.0.78/ → cd bin → perform commands
a. ./ shutdown.sh
b. now, start the tomcat ./startup.sh
LA
K KA
HI
PC
EE
Now, you will get the tomcat web page. This is Tomcat Web Application Manager
So, right now what we need to do is we have to send our war file to Apache inside webapps folder
ND
So, for that one go to target folder and copy the path by using “pwd” command
But here, we have to change the owners of the file. Because, for war file we’re having jenkins owner
SA
and for webapps folder we’re having root owners
we have to change the webapps owners
Go to apache folder → webapps → perform this command → chown -R jenkins:jenkins webapps/
And again here, root and jenkins directory are separate. So, we have to send apache folder to
common directory i.e.., /opt folder
Go to home directory and perform this command → mv apache-tomcat-9.8.0 /opt
Now, go to → cd /opt → we have apache folder and everything
Now, we are good to copy the war file into webapps folder
Go to pipeline script and add deploy stage like given below image
S
IN
Now, save & build and open tomcat browser, you will get output
NK
JE
LA
K KA
HI
PC
EE
ND
SA