DevOps Project Setup By Mr. Ashok | CI CD Pipeline @ashokit

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
good morning guys today we are going to set up cacd pipeline by using jenkins so as part of this setup we are going to use several tools first our project is available in github github is a repository where the project source code will be available so we'll take a project from the github that project is created by using maven in order to build and deploy that application we are using one software jenkins in the jenkins we are using cicd pipeline concept cacd pipeline concept we are using what this is jenkins software is going to do today this jenkins software is going to clone the repository from the github jenkins is going to clone the repository from the github and jenkins will communicate with maven jenkins will communicate with maven maven is a build tool it is used to perform build process for java applications jenkins will clone the repository from the github maven will compile and package our java application after build process completed i mean clean and package goals execution completed jenkins should communicate with this sonar cube to perform code review sonar cube is code quality checking software so i want to perform code review of our application by using sonar cube after code review completed i want to upload the build artifact into nexus repository i want to upload the build artifact into nexus repository sonar type nexus repository after uploading the artifact into nexus repository i want to deploy the application war file into apache tomcat server tomcat is a container which is used to run our web applications so tomcat we are going to use as a server now my jenkins is responsible to communicate with all the tools to automate application build and deployment process in order to perform all these steps we are going to create a pipeline in the jenkins we are going to create a pipeline in the jenkins all right so here our jenkins pipeline that is called as cacd pipeline contains several stages so in this pipeline first stage i'm going to take it as clone git repository and second stage maven build second stage maven build third stage code review with the sonar cube and fourth stage fourth stage upload artifact maven build code review upload artifact upload artifact and stage 5 is deploy to container deploy deploy application so i want to create a jenkins cacd pipeline with all these five stages now in order to create a pipeline with all these stages what are the requirements what are the prerequisites now the prerequisites we need to have a git repository so let me go to my github let me show you my git repository so here i have a git account in this git account i have a project maven web application this is my git repository git repository is ready then we need tomcat server so i have created a linux machine in that machine i installed tomcat server i created a linux machine in that machine i installed tomcat server let me connect to this machine and start the tomcat server go to mobi extra go to mobi extra connected to this machine where our tomcat server is available remote host user name easy to user private key and public key yeah linux.com connected to the machine in which our tomcat server is downloaded fine ls iphone l you can see that apache tomcat nine point x is available cd space apache space apache slash bin inside the bin we will have a file to start the tomcat startup dot sh so there is a file called startup.sh so now sh is space startup.sh it is used to start the tomcat server tomcat server started you can see that tomcat started how to access this tomcat server copy this public ip of the tomcat tomcat server runs by default on the port number 8080 yes i'm able to access my tomcat we already configured username and password in the tomcat users so let me login with credentials that is admin console of the tomcat so in this tomcat there are some applications already deployed i am undeploying all those applications so there are some default applications are available my maven application is currently not deployed in the tomcat whatever the applications that you see these are the default applications so with this my tomcat server is ready so i can say that my tomcat is running in one linex machine so this is public ip of my tomcat machine or i can say this is the url of my tomcat http colon double slash http colon double slash public ip colon 0 tomcat server url next git repository so we have project in the git it is a maven project so i can say this is my repo url this is my repository url perfect next one sonar cube we have taken a linux machine in that linux machine we installed sonar so sonar is sonar server this is a linux machine that machine is running let me connect it to this machine session ssh remote host username ec to iphone user ssh setting use private key pam file ok we connected to the sonar machine in this machine sonar server installed cd slash opt sonar cube ls iphone l cd space bin cd space bin ls iphone l cd space linux ls iphone l sonar dot sh available sonar.ssh sonar.sh there is a shell script file available which is used to start the sonar in this machine we created one user with a name called sonar with a name called sonar we created a sonar user as well sudo su now su iphone sonar i switch it to sonar user guys i switch it to sonar user using this sonar user it is best practice to create the user in the linux whenever we are installing a software i created a sonar user then i have installed sonar in this machine now let me start sonar machine so currently i logged in into this machine as a sonar user i switch it to sonar user now you can see the path you can see the path you can see the path of that machine right now here we are going to we are going to start this we are going to start this sonar software ls iphone l we switch it to uh okay fine one second we switch it to sonar user so the present working directory it is giving us slash home slash sonar actually the sonar is installed in opt sonar directory like sonar directory bin then linux so this is my present working directory where the sonar software is available ls iphone l in this present working directory sonar dot sh file is available let me start the sonar sh space sonar dot sh space start it started sonar cube now what is the default port number of the sonar server guys do you remember what is the default port number of the sonar server nine thousand nine nine thousand nine thousand so i'm trying to access this machine where the sonar server is running so public ip colon 9000 am i able to access sonar now if you are unable to access please check your security group you need to enable you need to enable nine triple zero port number in the security group you need to enable nine triple zero in the security group tomcat also tomcat server runs on the port number 8080 sonar server runs on the port number nine triple zero in this sonar server already i have analyzed one project good now my tomcat server is running my sonar server is also running let me take the url of the sonar so this is sonar server url it is running inside one linux machine it is running inside one linux machine good next let me go to nexus repository nexus repository it is used to upload artifact okay nexus server is also running nexus server is also running so in this nexus server in this machine this nexus server this is just a machine name linux machine in this machine nexus repository server got installed what is the port number what is the default report number for nexus repository guys 8081 the default port number for nexus repository is 8081. let me login let me login into our nexus repository yes admin admin admin is the username and i have selected password also as a admin so we have nexus repository in this nexus repository we created snapshot repository and we created release repository we can go to browse we can see snapshot repository last time when we discussed about the nexus repository server we uploaded our build artifact into nexus we uploaded build artifact into nexus good fine so with this our nexus repository server is also ready nexus repository server is also ready maven project which is available in github repository we have taken git repository url we have taken a linux machine in that linux machine we installed tomcat this is the url of our tomcat server tomcat server runs on the port number 8080 we have taken a machine in that machine we created sonar user and we installed sonar software this is the url of our sonar server sonar server runs on the port number 93.0 that is the default port number and we have taken one linux machine in that machine we installed we created an access user and we installed nexus repository server nexus repository server runs on the port number 8081 good fine so we have all the prerequisites now sonar cube server is available nexus repository is available under tomcat is available our github is available next we need jenkins machine we need one machine where jenkins will be available using that jenkins we are going to create the pipeline with all these stages to automate build and deployment in the last session we have taken one ubuntu machine in that machine we installed java jenkins software developed by using java so first we need to set up the java then we can install jenkins so here i have installed java using apt-get package manager and i added jenkins keys then i installed jenkins so when we install jenkins it will give you the default admin password in this location i have taken that password my jenkins server setup is ready with these commands all right let me access the jenkins server this is the url this is the public ip this is my jenkins let me log out let me show you once again this is the public ip of the machine in which my jenkins server is running jenkins runs by default on the port number 8080 guys all the port numbers eight zero eight zero nine triple zero eight zero eight one you need to enable in the security groups let me login into my jenkins this is my admin account ashok iit yes i'm able to login into jenkins machine so currently i don't have anything in the jenkins now my jenkins machine is ready my jenkins machine is ready my github repository is ready which is created by using maven maven project maven project which is available in the github sonar server is ready nexus repository server is ready tomcat server is ready so all the infrastructure is ready now we need to create a pipeline using that pipeline we are going to automate build and deployment of our application in this pipeline i'm going to create these five stages stage one clone the repository stage two do the maven build stage three perform the code review stage four upload the code into nexus repository that is build artifact stage 5 deploy our application perfect before going to do this we need to set up a maven as a global tool in our jenkins so here i'm going to global tools configuration in the jenkins dashboard you can see one option called manage jenkins in the manage jenkins there is a option called global tool configuration in the global tool configuration you can find the maven settings here maven maven installations so you can add maven installation here i have given the name of the maven as maven iphone 3.8.6 so my maven version is 3.8.6 that's why i have given the name as maven iphone 3.8.6 so as i configure this as a global tool it will directly download that maven 3.8.6 version from apache that's it apply and save guys remember maven i'm not installing on the jenkins machine maven i have configured as a global tool in my jenkins that's it next let's go to new item let's go to new item so here i'm going to create a pipeline so here i'm creating the pipeline as project pipeline project pipeline so generally we can call it as a dev pipeline whatever the suppose if this project is a application like ashok id application ashok id underscore dev underscore pipeline associated dev pipeline so i want to deploy the code into one server let's assume that that is a dev environment dev server so i'm giving the pipeline name like this select a pipeline click on ok all right so here we can give the description about our pipeline and we can select some options available build triggers advance the project options pipeline script is available now here we need to write our pipeline script here we need to write our pipeline script right now i am going to write this pipeline script so here i am starting that with node or you can use pipeline node now inside this note i'm going to specify stages my first stage is clone repo my step first stage is clone repo i want to clone the project from github repository so if i directly configure this url is it going to clone that get to clone this url if i directly give this command git clone repository url is it going to is it going to clone that repository no no sir yes in order to clone this repository we need to provide credentials is it recommended to specify the credentials in the build pipeline no it is not recommended to specify the credentials in the build pipeline we need to hide the credentials in the pipeline to hide the credentials in the pipeline you can use one option pipeline syntax now click on pipeline syntax here we can generate the script to hide our repository credentials so sample step what is our step in the pipeline clone the repository from the git right here you give your repository url take this url give the repository url specify from which branch you have to clone the code so in the git we discussed about branches so currently master is the default branch in this repository so i am giving the repository url and i am giving the branch name credentials so if you have already configured the credentials in the jenkins you can select it if not you can add the credentials here your github repository username and password you can add and you can save once you save the credentials you can select those credentials i have already saved my github credentials in the jenkins so i will select get credentials option fine i have selected sample step as a git and i am giving the repository url my branch name i am giving as a master these are my git repository github account credentials using these details i'm clicking on generate pipeline script see here get the credentials stored get the credentials i stored in the jenkins to access those credentials i am taking this id so this is my repository url these are my credentials using this approach we can hide the credentials in our build pipeline so this is my first stage git credentials and url let's apply save and run the job run the pipeline and see our first stage is working as expected or not so here once the pipeline is created there is the option called build now when we click on build now we can see the status guys is the status success or failure success success the build status is success we can go to console output so this job is executed by this user it is running in the jenkins machine running in the jenkins machine final status of the build is a success it is able to clone the repository from the github it is able to clone the repository from the github so we completed one stage now we need to go for second stage that is maven build right so i need to edit the same job click on configure we can edit the same job go to our pipeline now we need to write second stage in the pipeline go for stage let's do the stage creation maven build inside this stage i need to tell to compile and package our project compile and package our project guys do you remember what are the goals available in the maven to compile and package our project yeah clean and package now can i directly execute those commands mvn clean and package let's try let's try i want to execute clean and package goal sh space mvn clean package apply save now let's try to run the job build now now our job contains two stages one is clone the repository second one is maven build now see my second build success or failure failure on the second step it fails first step success cloning the repository stage got success maven build got failed when the build is failed can we see the reason for the failure yes go here and check console output running the jenkins now first stage got success and second stage failure what it is saying guys what is the reason for the failure it is trying to execute mvn it is saying that mvn not found so what is the meaning of that it's not initial maven software is not available in this machine wherever our jenkins job is executing in that machine maven is not available this is jenkins server or this jenkins machine where our jenkins job is getting executed it is not able to locate where is the maven it is not able to understand what is this mbn maven is installed in the jenkins machine directly are maven added as a global tool global tools global maven added as a global tool is jenkins able to recognize where is that maven available is jenkins able to recognize where is that maven available jenkins not able to recognize where is the maven available maven we added as a global tool now we need to tell to the jenkins that maven it has to use from the global tool in my jenkins machine maven is not available mavin added as a global tool in the jenkins i need to provide that information to the pipeline i need to provide that information to the pipeline in order to provide that information to the pipeline we can use these steps so maven home tool name is maven iphone 3.8.6 this is the name i have given type is maven so maven home will be available inside the slash bin mbn will be available so this is the location where the maven is available using that location it has to execute my clean and package you have to specify your global tool information you have to specify your global tool information in the pipeline then it will locate where is the maven maven home tool name maven name that we have given in the global tool type of the tool is maven so maven home slash bin slash mvn so when i want to execute this maven goal i am giving this location and i am configuring the goals click on apply click on save now run the job again build now third step third stage i'm executing starts time third time i'm executing sorry now so when i execute this when i execute this build status is a failure our build status is a success success so cloning the repository is a success under maven build also success go to this build number and see the console output see the console output cloning the repository then after cloning the repository maven clean package now see from where it is taking maven from where it is taking maven is it taking the maven from the linux machine or it is taking a maven directly from the jenkins from jenkins so we installed maven as a global tool we installed as a global tool we have given path of the maven so from this path it is able to recognize what is the mbn and it is able to execute maven goal so maven goal clean compile now the maven goal is executed this maven project is a web application so build plugin war plugin executed and our project packaged as a war file where is that war file inside the project target folder that war file got created my build is a success the job finished with the status success so with this two stages completed cloning the repository completed and maven build also completed get to clone completed maven build completed all right next what is the third stage now excuse me sir yes sir is this is the script specific to scripting pipeline or we can execute in our declarative pipeline we can execute anywhere right yes we can do that we can do that now my build got success my bill got success next go to configure what is the next step guys what we need to perform code review we need to perform code review so code review we need to perform by using sonar now i need to integrate jenkins server with sonar in order to integrate jenkins with sonar here i have given some steps connected to the sonar server and run the sonar by using this command already our sonar server is running our sonar server is running this is the url of the sonar the port number is nine triple zero now how to integrate jenkins with a sonar how to integrate jenkins with sonar in order to integrate jenkins with sonar there is a plug-in sonar cube scanner plug-in we can use a plug-in called sonar cube scanner plug-in good now go to manage jenkins go to manage plugins here go to available section you can type sonar you can type sonar you can see a plugin with a name called sonar cube scanner are we able to find out the plugin manage it manage plugins in that we have a sonar cube scanner plugin select this plugin install without restart install the sonar plugin without restart installing plugins sonar plugin is getting installed it is taking time guys yep the sonar plugin installed successfully sonar plugin installed successfully right here we need to configure sonar with our jenkins we need to configure sonar with our jenkins guys last time when we discussed about sonar how many ways we integrated sonar with our java web application token is the recommended approach do you know how to generate the token yes sir do you know how to generate the token yes yes let's login into our sonar let's login into our sonar let's go to my account let's go to my account security so we can generate token here we can generate the token now let me give you a name ashok id now copy this so i generated a token i generated a token so token we need for this so i have generated a token guys so let me take this as my token let me know down this so this is sonar token i need this token to integrate jenkins with sonar sonar token once it is done generate sonar token and add it as a secret text in the global credentials so now in order to integrate sonar and jenkins so i am going to create configure global security configure global security global credentials we are going to configure good configure global configure credential provider manage credentials go to manage credentials so currently jenkins available stores to scope it to jenkins github credentials are available currently and we need to add our sonar credentials also sonar credentials also one minute dashboard manage jenkins global security this is for permissions not here so using snip snippet we can't get it like whatever we will do that in order to do that first we need to configure the sonar credentials right okay how we added git credentials similarly we need to add our sonar credentials there is a token for that let's try to add it directly let's try to add it directly if not then we will add it as a global credential now here we need to configure sonar manage jenkins configure system configure system we need to configure the solar server in order to generate the pipeline syntax first we need to configure this sonar guys i have started sonar and i have taken sonar token i installed sonar plugin now i need to configure sonar in my jenkins for that we have option configure system in the configure system you can find sonar cube servers and sonar cube installations do we have the option sonar cube servers add sonar cube do we have a option in the configure system i'm going to manage jenkins manage jenkins configure systems now i need to configure sonar here when you scroll down you can see sonar cube servers add sonar cube add sonar cube you can give any name for the sonar cube i am giving the name as sonar server 7.8 our sonar server that we are using is i think 7.8 version of the sonar we are using yep version 7.8 sonar software community edition sonar software we are using version 7.8 i am mentioning the same name sonar server 7.8 url of the sonar we have taken the sonar url my sonar server running in this machine take the url of the sonar now here it is asking sonar authentication token sonar cube authentication token mandatory when anonymous access is disabled so click on add so when i click on add is that button working here guys is there a button working no no so here in the drop down are we getting any credentials no no are we getting any credentials no so we are not getting any credentials i think there is a bug here we are not able to click on this add button we are not able to click on the add button so for that what we do is we will add the sonar credentials we will add the sonar credentials as a global tool configurations yes right manage jenkins manage jenkins edit those credentials in the global credentials configure global security manage credentials credential provider one minute so can you see any option credentials configure credentials here get credentials available username with password jenkins credentials provider this is git credentials yeah fine i got it now guys see here when you go to credentials now when you select global here do you have your option called add credentials yes do you have your option called air credentials here yes we have the option called add credentials here so now let me show you once again go to manage jenkins in the manage jenkins there is option called manage credentials when you click on the manage credentials here jenkins global option already git credentials we have added if you click on add credentials you are getting the option add credentials now i need to add the credentials credentials we are adding with username and password or we are using we are using secret token token we are using secret secret token so here can we say as a secret text now yes yes can we can we add it as a secret text yes we are adding as a secret text so here i am giving the secret text sonar cube token we have taken this is our sonar token copy this token give this a secret give this secret id i will mention that as sonar token i will mention that as a sonar token scope we are giving it as a global sonar token and we are adding as a secret text in the global credentials click on create so with this i have added sonar token with this i have added sonar token let's go to configure system once again configure system come to sonar can you see that whatever the sonar token we are added are we able to access that in the drop down yes sir we are able to access that in the drop down now let me give the name for that sonar server 7.8 and the url of the sonar the url of the sonar this is my url guys please remember we are using currently ec2 t2 micro instances medium instances public ip public ip is a fixed ip our public ip is a dynamic ip public ip is a dynamic ip when i restart my machine ipv will change and ipv will save changes if you want your fixed ip address in the aws ec2 we have a elastic ip concept fine now i have given the name as sonar server 7.8 server url this is the url of my sonar server authentication token sonar token i am giving click on apply click on save so with this i configured sonar server with this i configure sonar server now let's go to our pipeline let's go to our pipeline in this pipeline now i need to add sonar stage in this pipeline i need to add sonar stage go to here add next stage code review code review in this stage i need to write some logic which is used to communicate with the sonar server and perform code review fine for that can we use pipeline syntax to generate the code yes yes can we use pipeline syntax go to pipeline syntax go to pipeline syntax see do we have any option for sonar see do we have any option for sonar see the option for sonar [Music] node retry stash weight unit with the ant with gradle archive get context with context after installing that sonar we should get one option with the sonar cube environment with the sonar cube environment for sonar cube analysis to be completed and return quality gate status that is the wait for quality gate sonar token generate pipeline script no this not this one so this is something different plugin so you have to go with specifics build one minute i'm checking a plugin for that yeah let me choose this wait for quality that is the not that plugin sir wait for smaller cube analysis to be completed no not that with the environment i have given some name for the sonar so let me do this this is the plug-in stage sonar cube analysis with the sonar cube environment that is what we are going to use and whatever the sonar name we configured that we are going to use now let me go here to the pipeline inside the stage code review uh i'm going to use with sonar cube env with sonar cube environment in this we need to specify the name that we used for the sonar what is the name that we used for sonar in the global configure system manage jenkins configure system in the configure system we have given sonar server what is the name we have given sonar iphone server iphone 7.8 so the same name i'm going to specify sonar server 7.8 so now we need to perform the code review by using sonar do you remember what is the goal that we use to perform the code review raven sonar columns maven sonar colon sonar where is maven do i need to specify this maven location we installed as a global tool so earlier for maven build we used clean package now we are going to use a goal stolen now how this pipeline will understand where is the sonar and what are the credentials of the sonar that is where we are giving sonar server 7.8 what is this sonar server 7.8 can i say it is a name where we configured sonar server url and sonar token yes yes yes or no yes sonar server 7.8 in this sonar i have given the url of the sonar and i have given authentication token of the sonar so in order to perform this code review i am using with sonar cube dnv i have given my sonar server name which i configured as a system in the jenkins then i have given the location where the maven available maven we installed as a global tool so once it is able to detect where is the maven then it should execute sonar colon sonar what is the purpose of sonar colon sonar it is used to perform the code review click on apply click on save before going to run this pipeline now can you see in our in our sonar there is one project already so if you want let me delete this project delete it yes projects currently in our sonar how many projects are reviewed available currently now go to our pipeline let's run our pipeline build now this time we are having three stages in the pipeline clone the repository do the maven build and perform code review three stages available code review third stage is executing go to the build number go to the building global configurations so go to the build number see the console output still the build is in progress so cloning is completed and maven build completed successfully then what it is doing guys is it able to communicate with the sonar yes yes yes yes yes sonar server 7.8 is the system that we configure configure system we used there we configured our sonar server name sonar server url and sonar token and in the sonar stage i have given a plugin sorry i have given a goal sonar colon sonar mvn sonar colon sonar now it is downloading all the required dependencies to execute that maven goal maven dependencies it is downloading to perform that code review finally what is the status of the build success build success build success so it is saying that analysis is successful you can browse your sonar dashboard using this url yes build finish its status with a success now go to our sonar server and refresh it can you see one project code review completed now yes sir maven web app project code review completed earlier there are no projects i have deleted all the projects from the sonar now when i execute my build it is saying that one project code review completed successfully when you open this project it is saying that there are four bugs available in the project and the code quality of the project is passed so with this are we able to integrate are we able to integrate our jenkins and sonar in the pipeline yes sir we are able to integrate our jenkins and sonar in the pipeline how we integrated jenkins and sonar in the pipeline so first we started sonar server sonar is running in a separate machine then we generated a token for the sonar then sonar cube scanner plugin we installed in the jenkins and we added sonar token in the global credentials then in manage jenkins we have a option called configure system in that sonar cube server we have added for that you can give any name we are using sonar server 7.8 version so i have given the name also with the same name same version this is url of our sonar i am giving that sonar url then we are selecting the token we are selecting the token once the sonar is configured in this manage jenkins then in the stage we can write sonar cube analysis with sonar cube environment this is the stage that we are using in that i am specifying sonar server name whatever the name you give here same name you have to specify then jenkins will find out what is the url of the sonar and what is the token of the sonar in the configure system we added sonar with a name url and token same name i am configuring with sonar cube environment here then my jenkins will identify url of the sonar token of the sonar if url and token available can we communicate with sonar yes now in order to communicate with the sonar we are using sonar colon sonar gold sonar colon sonar gold so sonar colon sonar is a maven goal sonar colon sonar is a maven gold for that we are giving the location where the maven is available maven we installed as a global tool we are giving the path of the maven and we are executing sonar colon sonar guys last time when we lend the sonar server we configured sonar url and sonar token in the palm.xml but this time are we doing that are we making that are we adding that sonar in the palm.xml no no sir do we have that sonar url and token in the palm.xml of the project so in jenkins we are integrating directly is this clear yes perfect yes sir next what is the next stage in our pipeline facebook upload artifact upload that what is the next stage upload upload uploading artificial accessory yes to upload the artifact in some companies people will use nexus in some companies people will use jfrog so currently we are using wichita factory server nexus we need to integrate our jenkins with nexus we need to integrate our jenkins with nexus now go to our jenkins go to jenkins our last build success repository cloning maven build and code review also completed successfully next we need to integrate our jenkins with nexus repository to upload the artifact for that first let's install a plugin nexus repository plugin is required guys go to manage jenkins go to manage plugins go to available section type a option called nexus can you see nexus artifact uploader plugin yes yes seriously yes we need this plugin because jenkins is running in one machine nexus is running in one machine separate machine jenkins from jenkins machine we need to upload the artifact into nexus for that we are using nexus nexus artifact uploader plugin let's select this plugin install select the plugin and install that plugin will act as a mediator between our jenkins machine and nexus machine nexus machine perfect guys in this project version is available as a snapshot okay fine yeah nexus plugin nexus artifact uploader plugin installed successfully so once that plugin installed successfully then go to our pipeline go to our pipeline configure now we need to add a stage in the pipeline we need to add a stage in the pipeline upload artifact stage name can be anything upload artifact we can say that upload build artifact right now inside this build artifact we need to write the logic right so do we know how to write that logic we don't know can we take the help of pipeline syntax guys can we take the help of pipeline syntax yes click on pipeline syntax go to sample step check it here do we have any option to upload the artifact one minute yes do we have any option sample steps what is the first option what is the first option gas can you see one option can you see one option guys next artifact uploader yes sir yes there is the option called nexus artifact uploader select this nexus artifact uploader we are using this is a step that we are using to generate the code pipeline syntax to generate the pipeline syntax we are using nexus artifact uploader perfect guys carefully observe carefully yes sir tell me yeah so for the sample steps so then we have multiple options right so the automatically it will come our so after we are going to install the plugins it will come after installing the plugins it will come okay so that's why we installed the plugin right okay right after installing the plugins we'll get that now i installed nexus plugin then i got nexus artifact up that means few plugins will come by default i mean few options will come by default few options we are installing right so let's select nexus artifact uploader here where is that yeah nexus artifact uploader i'm taking guys here we need to provide all the information to generate the pipeline syntax for nexus artifact uploader which version of the nexus we are using nexus 2 or nexus 3 guys which version of the nexus we are using it is 3 nexus 3 so here we need to select nexus 3 what is the protocol we are using http protocol nexus url nexus url so we need to specify the url of our nexus server so we have noted down already nexus server url here this is our nexus repository url nexus server running on the port number eight zero eight one so now coming on the screen nexus repository url can you see the nexus url now yes yes next is url credentials do we have the credentials for the nexus admin and admin right so click on add username with password the nexus username is admin password also i have given as admin so i am going to configure i will give the name as nexus credentials description click on add select nexus credentials now whenever we are uploading that artifact what is the group id and what is version and what is repository that it is asking what is the group id and what is the version and what is the repository it is asking got it now here group id we can give anything i'm giving the group id as in dot ashok id version so what is the version that you want to give for your project 1.0 iphone snapshot i want to give repository i am giving the repository name as ashok iit iphone snapshot i am giving the deposit name as ashok stampede this is the information that i am giving to upload my artifact into nexus when i am uploading my artifact what should be group id of my artifact what should be the version of my artifact and what should be the in which repository we want to upload the artifact in the nexus we have already created the repositories so remote repository and release repository snapshot repository so here we are having some repositories if you want i can delete this repository and i can create the repository once again so create a repository so maven repository i'm going to create unique identifier i'm giving ashok id iphone snapshot repository version policy so this is snapshot repository snapshot repository allow redeploy as well then fine click on create repository so with this i created one snapshot repository go to browse section click on browse ashok it is snapshot repository currently do we have any data in this repository or it is brand new repository there is nothing available here no components are assets found in this repository currently it is a brand new repository that we created just now good ashoka it is snapshot repository this is the url of the repository this is the url of our repository good go to jenkins pipeline syntax so the repository name so what is the name we have given ashoka it is snapshot repository let me take this ashok id iphone snapshot repository artifact artifact id type classifier and file it is asking artifact id classifier and the type it is asking good artifact id that means the project name what you want to use i'm taking artifact id as zero one maven web app you can find that artifact id in our project form.xml artifact id is a zero one maven web app type what is the type of the artifact web application artifact will be var if it is a standalone application it will be jar currently we are using web application so it is var classifier i am leaving blank class where i am leaving blank file where is that file guys what file we want to upload what is the file that we want to upload war file war file where the war file will be created guys where the war file will be created target what is the file name it is generating it is generating a file with a name called zero one iphone maven iphone web app dot work zero one iphone maven iphone web iphone app dot war that is the name of our war file that is the name of our war file now click on generate pipeline syntax can you see whatever the options that we have given whatever the options we have given so i have selected sample step nexus artifact uploader nexus version 3 protocol http nexus url i have given nexus credentials i have selected group id version repository name artifact artifact id type is war war file location i have given then i have clicked on generate pipeline syntax it generated a pipeline syntax nexus artifact uploader just to copy this syntax go and keep in our stage go and keep in our stage so this is our nexus artifact click on apply and click on save click on apply and click on save so now how many stages available in the pipeline now how many stages available in the pipeline now four four changes already three stages we have tested they are working as expected now we added fourth stage now we added fourth stage click on apply and click on save then do build now do the bill now fifth build is executing stage one success stage two in progress that is also success stage three in progress showing fourth stage upload artifact what is the status success success go to build number five see the console output scroll down finished success finished success now here build status is a success but when you see the console what it is saying guys temporary failure resolution temporary failure in the name resolution go to this browse browse option snapshot repository artifact uploaded are artifact not uploaded not uploaded if you see the build console it is saying that temporary failure in the name resolution can you see there is a mistake double slash came in the url yes sir yes sir can you see the url double slash came in the url yes yes that means we have done something wrong in our pipeline syntax we have done something wrong in our pipeline syntax go to that pipeline configure go to the pipeline configure build pipeline sonar stage artifact id classifier file name type is the war credentials group id nexus url so this is a mistake guys at the end i have given slash at the end i have given slash in the url let me take this out i think http also appending two times yes we will see that actually protocol is there russia protocol http we are giving again in the url we are giving a gdp one minute let me check this let me check this yes first let me remove that extra slash which is appended here in the nexus url i have given slash and we have given the repository name what it is doing is it is also adding one slash so let me remove the slash from the nexus url let's try that let me remove slash in the nexus url based on the nexus url based on the nexus url and based on the repository it is preparing the url to upload the artifact right so i have removed slash click on apply click on save now do the build now run the build i made the changes to our pipeline script i have removed that extra slash sixth build is running sixth build is running go to the build console console output http yeah now see here what is the url got the problem with that double slash got removed now there is one more problem what is the problem now http appended two times so i have given the nexus url with the http protocol and protocol also i have given us http either you have to delete this one or we have to delete here got it if i delete from here now that means whatever the options we have given based on the options based on the protocol based on the repository based on the url it is preparing the url how it is preparing the url http plus nexus url plus repository it is preparing the url to upload the artifact now so from this url i am going to delete http from the url i am going to delete http go to configure in this artifact in the nexus repository url i will just give only ip colon port number i am just giving ip colon port number click on apply click on save then run the job build now seventh build we are running seventh build we are running go to build number seven see the console output scroll down perfect it's uploaded now can you see any issue here no no no so it is saying that clearly uploading artifact completed what is the proof go here refresh go here refresh now can you see our go to browse option go to browse option check your snapshot repository can you see the artifact is uploaded now yes can we see that maven war file is uploaded is uploaded when it is uploaded september 17 9 34 september 17 9 34 so just now the build artifact is uploaded into nexus repository how we generated the stage for nexus repository by using pipeline syntax so here you no need to give http colon double slash here in the url whenever we configure the url do i need to give this http colon double slash no no do i need to give the slash no so these are the two mistakes so giving at the right slash giving at the right http it is not taking so based on that today given this succession won't mention the https click on generate pipeline syntax now nexus url should contain only ip address colon port number protocol already we have given and repository name also already we have given based on this information protocol based on this information protocol plus nexus url plus repository they are preparing the final url and they are uploading that artifact into nexus repository finished success so with this we are able to complete four stages we are able to complete four stages cloning repository completed maven build completed code review completed upload artifact also completed what is the next one deploy the application to tomcat tomcat is running in the same machine our tomcat is running in a different machine now different ventilation machine tomcat is running in the different machine so in order to copy the war file from our jenkins machine to tomcat machine we need one plugin deploy to container deploy to deploy to container plugin that is different that is different so what is the deploy to container is deploy to container plugin we are using to upload the war file based on the server url here we are not going to use deploy to container plugin we will use a plugin called ssh agent okay what is the plugin name what is the plugin name we are going to use ssh agent is used to copy war file from our jenkins machine to tomcat machine web apps folder what is the duty of this ssh agent ssh agent is used to connect with another system from jenkins system i want to connect to tomcat system and i want to upload the war file into tomcat server for that we are going to use a plugin called ssh agent plugin guys fine now observe clearly how we are going to do our last stage in the pipeline go to jenkins dashboard manage jenkins manage plugins available can you install can you find a plugin called ssh agent plugin come on can you guys find a plugin with a name called ssh agent yes click on ssh agent install without restart i'm installing ssh agent plugin i'm installing ssh agent plugin fine plugin installation completed successfully go to jenkins to job go to our pipeline go to our pipeline configure go to the pipeline stage the stage i'm giving deploy deploy so now do you know how to deploy this by using ssh agent or we need to take the help of pipeline syntax guys can you respond you can unmute your mic you can respond yeah we need to take the pipeline we need to take the help of our pipeline sit click on pipeline syntax what is the sample step what is the plugin we installed what is the plugin we installed [Music] ssh agent we installed a plugin called ssh agent now here we need to select the credentials we need to select the credential ratios okay right guys now guys observe carefully i need to use ssh agent as a plugin which is used to deploy the application war file from jenkins server to tomcat server okay so click on add jenkins and i need to add the credentials what credentials i need to add okay no no no no no our tomcat is running in which machine same machine different machine different machine so tomcat is running in a different machine that is the ec2 machine so how can we connect to ec2 machine we are going to use it to connect with the ec2 machine okay now observe carefully observe carefully ssh agent click on add jenkins global credentials do you know the password of ec2 user no what we know so now here i will give it as tomcat server agent tomcat server agent what is the username of that machine easy to user private key private key where is our private key private key is available key pair is available right so linux is the pem file we used can we copy the key from this how can we copy the key from the pen file go to git bash go to git bash am i able to copy the pen file key yes sir yes now go here add it click on this add it click on add now am i able to get tomcat server agent now yes sir i'm able to get the tomcat server agent generate pipeline syntax yes so this is my ssh agent the name is tomcat server agent now using this tomcat server agent using this tomcat server agent i need to deploy the war file from my jenkins machine to tomcat server machine i need to deploy the war file from my jenkins machine to tomcat server machine in order to do that we are going to use the location of the file first where is my file available target zero one maven web app dot var this is my source where my file is available war file this is my war file location where i need to deploy this war file i need to deploy this war file in the tomcat so what is the location of the tomcat in the tomcat we have a folder called web apps folder present working directory so this is the destination in my stomcats machine tomcat server is downloaded and tomcat server is running this is the location of web apps folder in this machine i need to copy the war file i need to copy the war file into this location i can consider this as destination i can consider this as destination so this is source this is a source in the jenkins machine war file will be created in the target folder this is the source from this location i need to take the war file and i need to deploy that war file into this destination who is going to do that activity that activity should done by tomcat server agent that is ssh agent and i need to tell to this tomcat server agent my war file is available in this location and that workflow should be deployed into this destination so for that we are going to give the information or we are going to give the instruction for the tomcat server agent sh scp iphone 0 strict host key checking you no need to check any host key strict host key checking strict host key checking is equal to no then i am going to specify the location target and this file should be deployed into tomcat server this is the destination so what is that a tomcat server in the tomcat server agent i have just given the credentials i have not given the url of the tomcat so that the tomcat is available with a username as easy to iphone user then we need to give public ip of the automation public ip of that machine then slash slash this path this path okay ssh agent tomcat server agent tomcat server agent is used to copy the war file from jenkins machine to tomcat machine right sh sscp iphone oh strict host key checking is equal to no no need of checking any keys when we are copying the data from one machine to another machine here now target location of path the war file in the target directory war file will be available that war file should be copied into the tomcat machine in this location right ec2 user is the username this is the public ip and copy the war file into this destination what is the public ip of our tomcat machine public ip of our tomcat machine let me take this yes let me replace this here i am giving public ip so this is my ssh agent copy this ssh agent go to our build pipeline go to ssh agent go to build pipeline configure ssh agent in the build pipeline configure ssh agent in the build pipeline got my point now here sacp we have given iphone we have started with the iphone we have to close that iphone right let me close it yeah sh sacp iphone o target location easy to user get the rate public ip colon slash home slash easy to user apache tomcat slash web apps that's it click on apply and click on save so with this our pipeline is available with all the stages before going to run this before going to run this can you see in the tomcat manager admin console of the tomcat so list applications is there any maven application currently deployed guys can you see is there any maven application deployed in this location currently maven application is not deployed in this location no application is available currently in our tomcat next in the tomcat machine also we can see ls iphone l in the web apps directory can you see is there any war file available in the web apps directory guys can you see is there any war file available in the web apps directory no sir there is no war file available in the web apps directory now go to our jenkins pipeline now see the pipeline see the pipeline stage cloning stage maven build stage code review stage upload artifact already those are tested now first time we are testing our deploy stage click on apply save and bill now let us see the status eighth bill number is running it will not ask any context path we have given the path already right path i mean context path means uh whatever the war file name is available it will take that as a context path okay yeah so now what is this what is the status of this stage right go to build number eight console output scroll down scroll down scroll down what is this success now go to our tomcat list applications can you see maven application is deployed now can you click on this maven application is it running so whenever i run the job whenever i run the job so what happened the jenkins pipeline all the stages are executing jenkins pipeline all the stages are executing code is available in the github jenkins stage 1 cloning the code from the repository jenkins stage 1 cloning the code from the repository stage 2 maven build happened stage 3 code review happened stage 4 artifact uploaded stage 5 deployment also completed are we able to execute all the stages in the build pipeline now we are able to execute all the stages available in the build pipeline i will give you this complete pipeline step and nodes as well go to this build configure go to this build configure pipeline so this is complete pipeline script that we have created complete pipeline script stage cloning the repository git credentials we are hiding maven build maven we configured as a global tool sonar cube we configured as a configure system option and we are giving the maven path to execute the sonar google sonar goal sorry and we are uploading artifact into nexus we have given the nexus repository details and we are deploying the application into tomcat tomcat deployment we are doing by using ssh agent this is our entity and pipeline which is used to automate application deployment application build and deployment thank you
Info
Channel: Ashok IT
Views: 14,599
Rating: undefined out of 5
Keywords: devops project, aws project, devops realtime project, jenkins ci cd pipeline, jenkins multi stage pipeline, build and deployment automation, devops end to end project, devops cicd pipeline, best devops course, best devops aws training institute, devops realtime training, best software training institute in realtime, devops with aws project, devops aws interview questions, devops online training, aws cloud realtime project, devops practises, devops with aws by ashok sir
Id: qJ8gUp0O25k
Channel Id: undefined
Length: 83min 40sec (5020 seconds)
Published: Fri Sep 16 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.