4. Jenkins Pipeline - Build and Deploy a war file on Tomcat Server | Pipeline script for CI/CD

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello friends welcome back in this lecture we are going to see how can we write a pipeline script to build under deploy a ver file on Apache Tomcat system for this demonstration I have already set up your target system before start writing our pipeline script you just need to understand few concepts let me walk you through those this is my Jenkins console we have a pipeline job we were updating in our previous lectures let me open it so far we are just cloning the repository and building the same this is my AWS console where I have Jenkins on Tomcat system and my Tomcat system is up and running let me connect to the system this is my Jenkins server I'm connecting to my Tomcat system IP address and I'm loading my key pair then user name and let me change the terminal settings I'm just giving Solarize a dark so you can feel the difference comparatively Jenkins server and this is my target system and if you see I have set up my Tomcat under opt here you have your Apache Tomcat if you go inside here you have workspace directory we should copy our wire files into workspace directory and also we have bin directory where we can start our Tomcat services ok let me become a root and going back to OPD Apache Tomcat and LS if I do I have been directly over here under bin let me clear the screen LS under bin we have start up dot Sh at the same time shutdown dot a CH so start off dot Sh to start the services she had done dot Sh to stop the services at this moment my Tomcat services are running on my system you can see here this is Tomcat service and you can stop this by using this particular script and if I check again for services now it is not running these are default services now let me again start it dot slash startup that is H again it is running so this is how we can stop and start services let me clear the screen and PWD so I need to come here to start or stop my services now let me access my application from the browser because currently application is running so taking the Public DNS new tab : eight zero eight zero so this is my application Tomcat application which is up and running because we have started our services now we need to deploy our where file over here next to thing I am going back to my Jenkins server and if you do remember in our previous video we have executed this pipeline job where it cloned the code and build the code whenever it to build it generates the artifact nothing but we our file you can see that where file under River Jenkins server so usually it will be where Lib Jenkins so this is the default location under this directory you can find here directory called workspace and LS if I do here for each job there is one folder in our case our job name is pipeline job go inside to this one and clear the screen if I do LS you can see here again multiple directories are there if I do three it will display the what and all directory structures are there inside to this one and what and all files are there rather than here let me clear the screen and go inside the web app under web app we have a target directory if I run the tree here it just displays what is there again we have under target directory we have a web app dot where file so this ver file we need to deploy under web app location in the Tomcat system nothing but in this location all right that is one thing now to do this one we need to update our pipeline script make sure that it is going to take this ver well and get it to deployed into the web apps location in the Tomcat system to make it work we are going to use SSH agent plug-in on our Jenkins server this is going to helpful for us to deploy a ver file on Tomcat server we can also deploy a ver file on Tomcat server by using de plyto container plugin but that is for manual Jenkins job in this case we are using pipeline script so we should use SSH agent but in this video we are concentrating on pipeline we are going to see how can we do that one so let's open Jenkins I am NOT closing this pace and here go to manage Jenkins and manage plugins I think I have already installed my associate agent plug-in you can just search for SSH agent yep it is already installed in your case if it is not installed you can go to available tab and search for SSH agent alright now it is already installed now we need to generate code to deploy on our tomcat system for that let's go and click on the pipeline syntax where we are going to generate script for this and we need to choose SSH agent so if you scroll down yes SH yep you can see here SSH agent you need to choose this option next thing we need to login to our associate servitude apply our files right so to login we need to provide credentials if you do remember we have logged into our tankard system by using ec2 - user ok what I have done I have clicked over here I have provided the IP address and username I have given ec2 - user and I also loaded the key pair the key pair is this one devops project dot pin so we need to give this key as well as user to deploy on our tomcat system otherwise you cannot able to login so let's do that one so I'm adding credentials I think this is my previous system credentials just Jenkins here instead of username and password because I don't have password right I need to choose SSH username and private key I have private key even in your case whenever you are launching your system you download this private key so ID and giving deploy user and given description also deploy user ID username is ec2 - user right and here we are using key pair so we need to choose this option and add our key I have opened my dev ops project key already in the notepad this is my key I am just copying it and copy over here that's it and add this one now you have two users of course this is my old user we just created deploy ok there is a typo anyway deploy user and we should generate the script that's it now we have generated the script you can see here deploy user script and we need to update in our Jenkins here before updating that one we just need to create stage right if you do remember for each and every step we need to create stages so I'm just copy the streams same stage here I'm just removing this one and I am again copying the code this is our code and I copied over here all right now we should copy our ver file onto the Tomcat server right for that we are going to use a SCP command if you don't know SCP command a CP command is used to copy a file or directory from one Linux system to another Linux system in this case we are going to use the SCP command to do that activity now I am going to use the SCP command just to remove this one SCP command is something like this let me increase the size yes CP then file what do you want to copy if you do remember we have our file over here right sorry not this one here right under target by default it can identify the location of your job you see here PWD by default it can identify the location till here under here we have our file under webapp slash target slash web app dot where this path we need to give go inside to target and copy the path that is Weber / / target / where we are to where so we should copy that one over here so the purpose / target / web dot where that is our file name so this file I would like to copy on to tomcat server now on Tomcats are worried as a which user we are copying so you see - - user right so before this I will just give the SCP syntax so ACP SRC file then username username art IP : destination path okay this is how you need to give we need to give the SCP command so in this case I have already given the source file then remote user that is ec2 - user : and the IP address of our tomcat server so far we haven't used our Tomcat server IP address let's grab it IP then : and which location we would like to copy as I already explained we need to copy our way our file into this location right so this path we need to copy so PWD this one then slash web app right so what we are doing is we are just copying this file onto target server as a ec2 - user unto this particular location but one thing we just need to remember is this ec2 - user may not have access to this particular directories that's why we should do the full access to opt directory for ec2 - user let me do that one before executing this one so LS - yell if you see it is wound by root I am just going back and even going back here here ch1 - our ec2 - user you see - - user I am just giving the full access to my ec2 user this is recursively okay for time being we are giving usually we will give access to the application user and application user is used in our pipeline scripts so this is done and I am just removing and as I said in the previous lecture whenever we are using shell commands or unix commands we need to specify it under SH so SH and we need to close it over here alright so this is how you can create over command now one last thing we should do whenever we are doing key-based authentication usually it will ask for the host key checking nothing but would you like me to allow to login or not so to disable that one we need to give the host key checking know so for that we just go to the pipeline's index where we have generated the script for ssh agent here if you click over here you can see SSH - whoa stick to host key checking so this we need to copy - whoa and this one if we do this one it won't ask for the host key checking so SCP here we need to give and we are copying over file and onto target system as a ec2 - user we have already given access to our ec2 - user account so and there is some problem with this particular script so let me check the syntax quickly so here we should have one more close so the stage and also we need to change the stage name okay we should not have the same stage name yep we have created one more stage and save so let's execute build now let me open the console output all right it is successful and you can see here ACP host key checking and it copied this is web app and if I go here and my application is running under web app okay if I give web app so it's not working okay are I found the error the problem here is we haven't specified the web apps over here we just specified web app but due to that one it is creating a separate directory in my Tomcat server that is the web app directly we should store it under web apps so I just updated it apply and let me validate it once again so it looks fine a play and say now let's rebuild this project build now this time the build should be successful okay so build is successful if I access my application yes you can see here welcome to Alex a technologist applying using Jenkins pipeline it was just added this content to validate it whether it's working fine or not we are going to update our code quickly github that comes last ready and my repository my repositories HelloWorld Web App again webapp index dot JSP so here we are going to update this is the code it is just a displayed at this moment so I am just removing this extra line and commit our changes that's it let me rerun my Jenkins pipeline sorry Jenkins job build now okay so build is successful now if i refresh I should not see the last lane yes okay it means that our Jenkins biplane is working plane all right so this is how we can write our Jenkins pipeline to build under deploy on Tomcat server that's all for this lecture if you like this video just give you a thumbs up and if you haven't subscribed to our YouTube channel yet please check out our content once if you like our content subscribe to our YouTube channel thanks for watching until next time
Info
Channel: Valaxy Technologies
Views: 37,442
Rating: undefined out of 5
Keywords: aws, devops, valaxy technologies, security, automation, serverless, lambda, jenkins, jenkins pipeline, pipelie script, declarative pipeline, deploy war file on tomcat server using jenkins pipeline, jenkins pipeline to build and deploy war file on tomcat server, jenkins declarative pipeline to deploy on tomcat, jenkins declarative pipeline, ar shankar devops, valaxy devops, valaxy jenkins pipeline script, devops for beginners, devops complete course, devops realtime project
Id: G_UCeeb5EPc
Channel Id: undefined
Length: 16min 33sec (993 seconds)
Published: Mon Jun 29 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.