CI CD Pipeline Using Jenkins | Continuous Integration and Deployment | Intellipaat

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome to this session on continuous integration using Jenkins today I have some people who would be joining us from the webinar and this is also a Youtube life right so we're gonna go ahead and start with this session right so guys if you have any doubts you can please comment it in the chat box for the people who are on the webinar and for the people who are on YouTube it would be great if we could put your comments in the chat box and we would be happy to answer all your queries now moving forward guys we let's discuss the agenda of this session so that we know like what all we will be covering today right so guys we will start off with what is DevOps and then we want to discuss what is a CI ICD pipeline once that is done we'll also discuss some of the DevOps tools that we will be using today to basically make the CI CI pipeline and towards the end we'll be creating an end-to-end seriously pipeline on the AWS platform okay guys now before I move ahead if you haven't already please subscribe to the in telepods channel right and click on that notification button so that if we create such videos for you you get the notification on your phone right and you can get access to that content as early as possible now let's move ahead guys and start with the first topic which is what is DevOps I can see I have some question on my code webinar so the guy says please cover the architecture with one demo to build pipeline yeah Morrigan we are going to do that right so let's go ahead and start with this session with the first topic which is what is DevOps so guys DevOps is nothing but it's basically a practice it's basically a way of bringing the developers and the operations team together right what that basically means is like developer is basically the team where you basically build the code you create all the tools that you need right and then you deploy it on the sole and for deploying it on the server it is basically giving given to the operations team which replies it on the testing server first where the testing is all performed and once the testing is performed it is then pushed on to production right so this is a very general way of saying that how an application is basically deployed on to a particular server right now earlier when the box is not there everything was done manually so developer used to be done with this book and he used to submit his code to the operations team and the operations team would then deploy the code on their machine and check if it's working or not if we choose to work there we used to push it for testing and when testing was done evidence everything was done they used to push it to the main server from where their application was basically hosted now this was in the ideal case but sometimes what used to happen was when the developers used to make their code the application did not run right and the reason could be anything for that it could be that the required software's are not installed in the ops machine it could be that the ops machine guy is basically using some other version of the software a sector there could be countless reasons as to why a particular program used to work on one machine and did not work on the other machine but this was basically a problem because developer used to be done with this book but still he used to get his code back saying you know it's not working on their machine and there is some issue with the code right and what we have seen is that there was a lot of problems between the developer and the operations team and it used to basically result in inefficiency in the whole software weapon process so we had to solve this and for solving this we came up with DevOps now what does DevOps a DevOps basically says that you know I I have a methodology wherein I will give you some tools you have to make use of those tools in a certain way which will basically result in no fighting between the developers and the operations team right so I will give you some tools using which everything will be automated you just push hold onto that tool it will automatically be tested it will automatically be deployed on to a particular server with the required software packages which are required for that code right and there will be no issues of code running on one machine and not running on the other because everything would be automated and if everything goes well I will also push it to production this is the whole story of what DevOps is now let's understand what is continuous integration now like I said in DevOps you use a lot of tools which work together to make DevOps possible right so let's understand what is continuous integration so guys continuous integration basically means I mean we are using a lot of tools but for integrating all these tools together you need one binding force right so that binding force is nothing but a continuous integration tool for example if you consider the following diagram which you can see on the screen there is a developer who basically used to work and use to commit his code onto a version control system right now what is that version control system that wasn't a draw system is nothing but it could be a github it could be a bit bucket it could be anything right so the vedele developer used to push this code onto a version control system and what happens is the continuous integration tool basically used to see if there is any change on the version control system if if there is any change it automatically you should detect it and to use to pull the code from the version control system and deploy it on the testing server ok on the testing server you used to have you know you have to used to have your own testing tools such as selenium which were basically triggered by the continuous integration server along with the part where the code used to be deployed on the testing server also by the continuous integration server so the code used to be deploy and then the test suit used to be executed by the continuous integration tool and the testing used to start right now let's say the testing failed and there is some log which came up that this is the error that you are getting the continuous integration server then used to forward that feedback to the developer saying that this is what the problem is with your code please fix it and the code was fixed the developer again used to push the code to version control system which again used to be pick up by the CI tool which again used to be pushed on to the testing server testing used to happen and if the testing succeeded it used to be pushed on to the production server so this is basically a very minified version of how a DevOps lifecycle basically works right and the heart of this lifecycle is the continuous integration tool which basically takes care of what is happening when where if if there is any change in the code it automatically used to trigger multiple jobs which used to perform multiple tasks and used to get the work done right so this is what continuous integration is because continuously you're getting the feedback continuously the developer is pushing the code continuously it is getting deployed on to testing and production that's why this life cycle is called continuous and what is happening it there is basically continuous integration happening over here okay now let's understand that CI to the magic tools that we were discussing what is that tool that tool is nothing much Jenkins so what is Jenkins in the most easy terms it is nothing but an open source automation so which is basically based on Java and it helps to automate tasks which are related to DevOps right so basically it makes way for the code from one life cycle stage of devoxx to the other and that's how everything used to work okay now let's go ahead and understand what are the features of Jenkins right so guys you have something called as an option you have something called as plug-in support right so adoption basically Jenkins is extremely popular it is popular because of the open source community which supports the Jenkins tool and hence you have a lot of documentation available for anything and everything that you want to do in Jenkins okay there are around so what the Jenkins can track is how many people are using Jenkins and by that people can take care that there are around 1 lakh 47,000 active which are basically happening throughout the world and are basically working with Jenkins and stolen this is basically there are one lap 47,000 servers which have Jenkins installed on them all right when you talk about the plug-in supports our Jenkins constantly get a lot of plugins which can be attached with Jenkins to basically improve its working to improve its functioning so the plug-in support is also awesome right so tires around thousand plugins which are currently available in the Jenkins repository on which you can install plugins and you can get their work done alright so it is very highly adopted among the development teams around the world and at the same time there are a lot of plugins which are also available up for Jenkins which does nothing but it extensa Faiz the use of Jenkins it extensa fires the features of Jenkins now let's move it and understand how we can set up Jenkins right so we will have to set up Jenkins on AWS so these would be the steps for it the first thing that we will be doing is we will be launching any ws instance followed by we will be connecting it through SSH and then we will be passing these commands in order to get Jenkins up and running okay so let me quickly jump on to my browser guys and then let's take it forward from there so just give me one second and I'll open the browser and now let's head on to AWS website alright now let's sign in to our AWS management console so once you sign in onto a table smash your console so guys if you don't have any SS account you can just click over here and create an inner bless account for you there are a lot of documentation available online you can head over to in telepods comm slash blog and there is a block called EWS management console which will basically help you to set up your AWS account right so you can head over to that and once you have the auto honk ready you can just log in with your email ID and then your password alright so what we need is an ec2 instance we will click on the ec2 service and basically we would be needing three servers we would be needing to source that is one would be the staging server we will check by putting our website over there if everything goes well and if it does we'll also push it on to the main server which will be our production server so the servers that will be launching would be Ubuntu servers guys so let's select the Ubuntu server the processor that we want is T 2 dot micro let's select that the number of machines that amount would be 3 right now let's go ahead and click on review and launch so I have a question so the question is what is upstream and downstream on Jenkins okay so Surya that is not part of the session probably you can what you can do is you can just drop a mail to support and I can tell you that separately but as part of the session I will just be focusing on CI CD pipelines right so if you have any questions with regards to what I'm doing currently you feel feel free to ask me all right now let's click on the launch button and now let's select the let's let's create a key pair and let's choose that key pair so let's say the keeper chickens right let's download it so we have a key pair downloaded and now let's click on launch instances alright so I have three server setup so the first server would be now let's say this is my Jenkins oh right and now let's set up the other two servers which are basically the staging server and then we have the production server alright okay guys good so now we have three servers which are set up right and these servers are ready to be connected to write it might take some time it might take a like a minute or so to get applied so the movement it is deployed we will try to connect to it all right so let's try on by connecting it with Jenkins server first because we first have to install Jenkins so the way we will be connecting is using the putty tool so this is a pretty tool guys you'll have to specify the IP address over here off the server that we are basically connecting to and then we have to basically select SSH and then auth and then we'll have to select the key pair through which we want to connect now the key PR over here guys it basically is for the PPK format so Sheila Kumar is asking me can we use same key for three source yes chilli so I'm actually using the same key for all the servers which is basically the Jenkins dot PEM file okay so this Pam file what I'll be doing is I would be first need needing to convert it into a PPK file the reason for that is that put t it only accepts PPK file now how do you convert it into PPK file is we have a put ijen tool which comes along with putty okay so what you'll have to do is you'll have to click on load and then you'll have to select the pen file which is basically you the file that you have downloaded so in our case it's jenkins to our pimp right so we have selected it and now you'll have to click on save private key so let's click on that and now it's asking me do I want to save it without prosperous I'll have to click on yes and now let's name the file something so let's try to name it as Jenkins right let's name it at Jenkins and the extension now as you can see is PPK let's save it on the desktop and let's click on save done right now what I'll be doing is I'll have to browse that same file over here that you'll have to go to SSH and then you'll have to click or not and then you rapper select the PPK that you want to connect to now the people get that I wanna connect to is Jenkins tor PPK here it is now I'll click on open and this will basically give me your terminal to which I would be connecting on right so this is the terminal let's login into it so since the operating system that I have you know that I have used is open to the username through which I will be connecting would also be open to alright so as you can see I'm logged into these over now and now let's start by installing Jenkins the first thing that I'll be doing is I will be updating the machine for that the command is sudo able to get and then update right so this will start off by updating the machine I also have a set of commands over here guys so if you want for the people on GoToWebinar what I can do is I can just copy these commands and I can give it to you so that you can practice on later so these are the commands just go through them and these would help you to install Jenkins on an Ubuntu machine alright so the machine is now getting updated it will take some time somewhere around a minute and once that is done since Jenkins is based on Java we first have to install the open JDK package alright so let's go ahead and do that so the updating is almost complete we'll also have to install Jenkins skies on the slave machines that we'll be connecting to Jenkins because if we are connecting Jenkins to a slave machine it will basically be through a protocol called jnlp right so we'll be using the jnlp protocol and which the jnlp protocol basically requires java so we would be using Java to connect Jenkins and the same machine so first let's install Jiang Java on our jenkins node so that's getting installed great so now Java is getting installed it will take some time so what we can do is while it is being installed let's launch our other servers as well this is a staging server let's connect to it so let's put in the IP address ssh auth and now let's also put in the PPK file which in our case is Jenkins alright and now let's open since this would resemble our Jenkins server let's change its color to something else let's change it to let's say yellow so I stating server is now yellow and now we would be connected to it great now let's update the machine so sudo apt-get update this will debate the machine and why this is updating Java is still being installed great I think it won't take much time over here all right so Java the machine staging server is now updated now let's install Java onto it and for that the command is over here let's copy the command and paste it here ok so Java is now being installed on my staging server as well it has finished installing on my Jenkins server awesome now let's see what our next mod is a next one would be to download the Jenkins package so let's do that let's download the Jenkins package alright it says now downloaded no shoes we can actually download it all right let's let's look at the documentation for installing Jenkins there could be that I missed out on some commands so installing Junkins on Ubuntu 18.04 now I personally Laffer the digitalocean documentation guys because it's pretty simple and it works most of the time right so we are on the step so W get let's use this particular command let's paste it over here and let's hit enter so it says no valid open PGP data found okay so this means this particular link is not working okay let's try some other documentation so install Jenkins to 18.04 let's try with this documentation so open JDK is something that we are installed and now it is expecting us to copy this key but I don't think anything would be changed okay this one works great so let me give it to the people on GoToWebinar so that they can also use it so guys for this key just use this particular command alright so I have given so now I have the key imported now let's go ahead and go on to a next step which is basically to cache the repository into the sources of our operating system right so let's do it done next step would be to update the machine so that all the Jenkins oil trees are updated so as you can see Jenkins packages are getting updated now done now let's go ahead and install Jenkins so this is the command for that let's go ahead and run this great so the Jenkins is now being installed well it's getting installed alright my staging server Jenkins the Java has completed installing let's similarly connect to our production system as well and let's install gel on that so this is the IP address let's connect to put teeth give the IP address over here give the auth file which is basically Jenkins toward PPK this and now let's hit on open let's change the color of the production machine to something else so that we don't get confused and let's use the color as let's say orange let's use a color as Orange let's click on apply right so this is my production machine guys let's update this machine sudo apt-get update right so the machine is now getting updated followed by installing Java so Java would be installed using this command right so we'll just put in this command it lasts for us confirm our confirmation will give yes and our Java is now being installed on my production server also let's see if Jenkins Latian finished so it's almost on the verge of being finished guys so let's wait for it to complete and once Jenkins has completed installation its installation over here will start the Jenkins service and then we will try to connect to it alright so as you can see Jenkins we have got the dollar prompt path which basically means Jenkins has been installed now let's go ahead and start the Jenkins server so this is the command for that let's copy it and now let's paste it over here great now let's check the status of our Jenkins service I hope that nothing goes wrong I think it should work well let's check the status but you never know what happens so yes it is in the active State great so now all I have to do is I'll have to go to a browser and I have to try to connect to the Jenkins server on this particular IP address now if I try to connect to it it will give me an error as of now because Jenkins okay so one more important thing guys Jenkins basically is available on port 8080 so I wrong with my IP address I'll have to specify port 8080 and now I'll have to hit enter okay so this will give me an error as of now and the error would be because I'm not opened the firewall of my systems to basically allow port 8080 so let's do that so in my AWS servers I will have to go to the security group and I'll have to select the inbound rules right so let's edit the inbound rules and let's add a rule and let's add the rule for let's say a custom protocol and the protocol not custom protocol but custom port so what we can do is we can actually give custom tcp rule and the port range is basically 8080 and now let the source would be basically anywhere all right let's save it great so now if I go ahead and if I guru port 8080 it should give back me a page right now this page will basically give me an odd or it will basically be an author page where I'll have to see there'll be a path over here and allowed to put the password from that path right so let's say this is the path that I've got so it says unlock Jenkins and for unlocking Jenkins this is the part so I'll have to basically echo whatever password I Kaito after internet over here right so let's go ahead and do that so I will be putting in cat and then the pot will give me an error it says permission denied the reason for that is we do not use sudo so let's sudo and then let's use this particular command again so this is the password let's copy it and let's paste it over here and let's now click on continue so now my Jenkins would be unlocked that's great and now it would ask me if I want install plugins so what I do is I would go ahead with install suggest edit plugins and this will basically install all the plugins required on the machine pretty fast so these are some of the recommended plugins by Jenkins they'll start installing and once installation process is complete we will go ahead and start adding nodes to champions so that we can basically create a pipeline out of it okay so let's wait for thinkin's to be installed and meanwhile let's head on to our pivot ease okay so we have executed we had launched an AWS instances we can exit through SSH and we have executed these following commands now let's go ahead and let's talk about the Jenkins architecture how does Jenkins basically work right how does it look like from the outside so that is Jenkins as you know it's basically a DevOps tool and Jenkins helps us to also integrate different DevOps tools using plugins okay so it has a lot of plugins in place we can use those plugins to do literally anything with Jenkins with regards to whatever possibilities are there in the box and Jenkins basically has its software installed on one machine and what you do is you connect the Jenkins master to testing server and the production server so that you can control what has to be done on the testing server and you can control what has to be done on the production server okay so now let's go ahead and see how we can actually set up this particular architecture that we just discussed let's just check if Jenkins is ready so it's almost done almost all the plugins are installed and let's just wait for a minute so for it to be complete and let's then add nodes okay so for managing nodes and Jenkins we first we would be basically connecting a node and the way we will be connecting the node is using the jnlp protocol okay now for basically connecting through geni the jnlp protocol what ill after enable is you'll have to enable you have to basically open all the ports between the server's so that they can interact freely so right now only two ports are open on all the three servers which is port 22 and port 8080 so all these three servers have one firewall which is in common with on which I just edited the inbound rules and that firewall can basically be used to basically add for the rules let's do that so let me go to the browser and let me go to the security groups of my EWS source so this is my security group guys and what I have to do is basically I'll have to add a rule over here so let's open all the puts let's do all traffic the source is very important the moment you open all traffic remember it only has to be opened between the three servers that we are using okay and for that what you can do is you can specify the IP address range over here or you can specify the IP addresses over here you can also specify you know let's assume that the machine then the other slave nodes that you've launched they are in some other security group right so you can also specify only the security group over here that will also work but since we are just practicing it and we look as to how divorce works we'll just give it anywhere and let's click on save but this is not how you would do it on production okay remember that now let's click on save let's head back to our slides and let's try to basically see let's if our Jenkins is now ready with its plugins yes so Jenkins has install the necessary plugins now because this is the first time we are setting up Jenkins will ask me to user names let's set up a set up the user name let's give it my name then let's give it a password and now let's also confirm the password over here and now let's give the full name the full name could be in telepods training and then the email address it could be any email address let me specify my email address over here and now let's hit on click on save and continue so this would do the final layer final settings of Jenkins and now I can use Jenkins by just clicking on save and finish right so it says Jenkins is ready so now let's click on start using Jenkins and we're all set to use Jenkins now guys so what we'll be doing now is let's go ahead and set up the notes that basically we would be controlling through Jenkins and the way to do that is by going into Jenkins setting and clicking on manage notes so let us give it the time so Jenkins is taking some time to load all right so it's ready now let's click on manage Jenkins so what you want to do is we want to manage notes right so let's click on manage Jenkins and once you have clicked on managing Kinsler's go ahead and check all the options which are available over there right so let's click on configure global security right so this is the first setting that you have to do this click on configure global security and over here you will have to change a value that is for the tcp ports which would be used to connect to your notes okay so let's wait for it load now you would find the reason as to why we've opened all the traffic for our machine and that is because this we have to enable so TCP fought for inbound agents so the value has to be random over here so will be it can pick up any random TCP port and through which it can basically connect to the nodes that we are using with Jenkins right so when you select random it can assign it any port that would basically mean it can assign it any random port through which it would want to connect and that particular port should be opened in the firewall and that is the reason we specified all traffic okay so just collect click on random and now let's click on save this is the only setting that you have to touch now let's go ahead and click on manage tones so there's one more option over here which is my national let's click on that so the only node that we have as of now is the master which this is basically as my Jenkins is installed right now let's click on a new node let's try to wire it right so let's give the new node name as staging right and you'll have to click on permanent agent and finally clicking on OK alright great so now you would get a screen which would look something like this so first you'll have to specify the remote to route directly let's specify it to be slash home slash open to slash Jenkins alright great then we will have to specify the launch method so the launch material has to be launched agent by connecting it to the master ok so we would be executing a command on the node and it would be connecting it on the master so this is the option that you have to select and that would be it nothing else is a mandate just click on save and now what we'll do is load the staging server over here great now you'll have to click on new node again because there are two nodes that basically you want to connect so let's click on your node again and now what I want to do is I want to click on basically I want to production so again click on permanent agent click on OK and then select the same options again so I want the root directory to be / / / 1 2 / Jenkins and the method would be launch agent by connecting it to the master and finally we click on save so now I have two nodes which are basically give me a cross because they are not connected as now so let's go ahead and connect them so first you will be clicking on staging and once you click on staging it will basically give you something like this now what is this this is the command that you will be executing on your server so that it can connect it to connect to the master right but there are two files that you will have to download one is this file slave agent dot jnlp that will have to download from the Jenkins tool over here and then the next is the agent or Java file right so let's go ahead and download it so let's click on launch this will download the chain LP file right and now let's click on agent dot jar this will also download the agent dot jar file now these files they have to be present on the staging server so let's see how we can basically copy it onto the staging server so there is a tool which is busy called FileZilla this is basically a FTP tool which you can use to copy data from your local system onto the server ok so what is the server that I want to connect to the server that I want to connect to is the staging server so let's connect to it this is the IP address let's copy it let's put it on FileZilla the username is the one tool there's no password the port is 22 and obviously you will also have to give the key which we use to connect with the SSH and that key will have to enter in the SFTP option so let's click on the SFTP option we'll have to remove this key and let's add a new key now so it's on the desktop and the key name is Jenkins dot PP care great so now everything is set up let's click on Quick Connect great so I am connected and this is basically the path or this is basically the folders on my server now what I have to do is I'll have to copy both these files which I've downloaded on the server and for that I'll have to just do a drag and drop into FileZilla and this would basically copy the file the first fire was agent watch out I'll get a notification which will go something like this and now now I have to do a slave agent not Jane have a lot of transmitter on the soul that fire also has transferred now if I go to my staging server which is the yellow terminal I'll just do an LS you can find that I have two files here these files will have to be renamed so let's do that so MV and then agent the char this I will have to change the name to agent torture oh sorry my bad so I have basically given comma it has to be agent dot char all right so if I don't win LS now agent or jar is now present let's similarly change this particular file right so we'll have to change the name of this file so let's do that into a slave - agent dot G and LP this is just because guys while I was downloading it I already had an agent or Java files in my folder so it put a bracket in front of it with one this is what Windows does when there is already an existing file with the same name so in your case you won't have to do this step so let's hit enter and now let's just do an LS and we can see that we have the two files that we need in order to connect great now let's just clear the screen and now let's pass the command that we saw in Jenkins which is basically this to get the work done right let's hit control C and now let's enter the command right so as you can see it says connected which basically mean my agent is now connected to my Jenkins server so stating server is now ready you can see that I am seeing the frida space I'm seeing the free temporary space I can also see the architecture on which the node is connected on right similarly let's do this for production let's click on production and now let's download the two files right let's try to connect to the production server so the production's IP address is basically this let's copy it let's connect it through FileZilla and then we'll transfer the files onto the file server so it says connection failed ok did fail because I'm not justify the port let's hit quick connect again alright so now I have the dike trees which are on the server let's copy agent 3 dodge are onto the server similarly let's also copy slayage in Dutch are over here alright so all the files have been transferred now let's hold head over to production server which is in orange let's hit LS and I can see that there are the two files there is I just copied right let's rename them so MV agent and I have to rename it as agent dog shot done similarly let's rename the slave fighter cell so I would be renaming it as slave - agent dot jnlp great let's hit enter done let's hit LS so I have the two files in place now let's go ahead and copy the command which is basically this great so now as you can see it says connected so I'm connected to my server if I go back to the list I can see boot production and staging are now ready ok so the metrics are not showing up for this particular machine as of now but it's showing up now so it's in sync this is the machine space which is empty right now and this is the response time that I'm getting from these particular service awesome now let's go ahead and let's start by creating a pipeline so what we'll be doing is let's create a new item and what we'll be doing is we'll be create doing a freestyle project let's name this project as so basically we between three job slices in Jenkins let me show it to you on the PPD so basically what we would be doing is we would be using git and we would be using taco right in the pipeline today so what would the gift and docker be doing so basically gate would have a half code of one website that we will be creating a very random website that we will be creating and that website will basically exists in gate right now that website we will be deploying using docker right so we would have to wrap that website so that would be done by Jenkins we would have to wrap that website with docker and that is how the whole thing is gonna work right but before doing that let's first understand what exactly is a CI CD pipeline if we understood that we want to use gate n docker but how do we do it let's understand it using the CI CI pipelines okay guys so a pipeline is nothing but it's basically a series of jobs which are executed together to get a particular work done which in our case is the first thing that we'll have to do is we will have to pull the code from gate and once we have pulled the code from gate we will have to deploy it on you using a docker file we will have to deploy it inside the rocker container build an image and once that image is built we'll have to deploy it right and once that image is deployed we will have to basically check whether the application is working or not if the application is working what we'll do is we'll also push the code on to the production server where again it will be built inside the docker image and then the docker image will be deployed all right so guys this is the these are the things that we will be doing but as you can imagine there are these are a lot of tasks which are happening so basically first we'll have to pull from gate then we'll have to wrap the code inside a container then we'll have to save that image then we'll have to deploy that image onto the server right so these are a lot of steps all these steps would be executed sequentially and that's what exactly a pipeline is right so a pipeline is nothing but a series of jobs that you accused in Jenkins which lead to a finished application all right or to a particular point which you can basically take and do something out of it for example it could be a finished testing application that you can test it's a application which is finished for testing and then there could be a production pipeline that you have created so that runs you know your application hasn't tested successfully you just push that application in that pipeline which is the production pipeline and then it gets deployed onto the production server right so pipeline is nothing but a series of jobs that you execute to get a meaningful task cut done all right now let's go ahead and see what are the things that we would be doing so that is we would be creating three jobs the first job will basically download the gate code to the particular server that is either the staging or the production server then we would be building the website so that website will be built by basically copying the code or building the code onto a darker country or wrapping the cord around a docker container and then creating an image and then deploying that image onto that particular server so once that is done we would be pushing I mean we would be testing the website on the ceiling server and F in the course rail it will then invoke the push to production job which will do nothing but it will also download the code under production and then it will deploy that particular website okay so guys these are the jobs that we are going to build so let's go ahead and start this okay so let's go ahead and create an automated CI CD pipeline so let's go ahead over to Jenkins ow so first job that we have to create is the get shop so let's specify that get - shop and now let's click on OK all right so this job will basically pull code from a particular great hub repository all right so what is that github repository let us create that repository here so let's go to github.com let's click on sign in so I have a get up a count guys you can also create your own github account it's free and then you can upload your code with that right so let's create a new repository over here let's clear apology which is called the website alright and now let's click on create poetry great so I have a positive in place now which is website kit now let's push code to this particular website how do we do that we'll have to head on to our server it could be from anywhere guys so I'm doing it from this server so let's create project over here let's say the project is website let's go inside the website directory and now let's create a let's let's basically create the website right so first we'll have to do create an index file let's say the index file go something like this this is the starting of the HTML this would be the title of the HTML say the title is Jenkins CI / CD pipeline let's close the title and now let's start the body off the webpage the body would have one header and the header of it cool like welcome to in telepods right let's close the header and now let's go is the body - finally let's also close the HTML and now let's save the file okay so the file has been saved what we would be doing is would be initializing a git repo here then we would be adding a github repository where we will be basically pushing the port right so the command for adding doing that is git remote add origin and then the URL of basically your github repository which in our case is basically this this particular link right so let's copy it let's paste it here let's hit enter and now that website has been added now let's stage our file which is basically the index file let's stage it let's commit it right let's commit the code and let's say added website right through the file has been committed and now let's push it on to our github so git push origin master last for the username let's enter that it'll ask for the password let's enter that and IO code has been uploaded onto github let's refresh it over here awesome so I have my index file over here if I click the index file this is the code that we have written the HTML file the title the body the h1 the clothes body and then d close HTML quick so now I have a website on this particular gate repository so what I'll be doing is I will be going back to the repository and I will be copying the link let's copy the link and let's come back to Jenkins so what do I want to do in this job which I was creating the good job the first thing that I want to do is I would be selecting the source code management option which is basically get and the URL is this this is where I would download from ok is there any particular branch so I have committed my code onto master so that is how we would be working on is there any bill triggers so yes we would be triggering the build using github hook trigger right and also I basically want to restrict this particular job to basically work on only the staging node okay this would only do it on the staging node this code will be downloaded on the stealing node this is the github that has specified the master will be built it will be built using github hook trigger and that is all I want to do right let's click on save great so now what I've done is I have created the get job which I had to do let's come back to our slides so the kit job is now complete downloads the get code to my slave which is basically the staging server the next thing that I have to do is the code that I've deployed I have to build it and it will be built into an Apache container ok for that I would need docker to be installed on this particular machine so let's duplicate a session for this machine and let install docker onto it okay so what I do is I type in sudo apt-get install Crocker dot IO right so this would install darker on the seeding machine let's do the same on the production machine as well let's install docker so production machine has the orange terminal let's duplicate a session over here as well and now let's install docker over here so the command is sudo apt-get install polka dot io all right so dr. is being installed on this server also okay so on this machine dr. isn't so let's check so sudo docker PS yes docker is installed so I have a question docker is installed only in slaves yes series because my website will be deployed on the slaves and it'll be deployed on docker so I just need docker to be installed on my slave machines nowhere else okay or I guess now let's go ahead and just check on our slave machine to on a production machine whether we have docker installed so yes docker is installed over here too great guys so docker is installed on both the slaves now let's go ahead and go head on to our git repository alright so I just have index or HTML now what I want to do is I want to wrap this website into a container now how would I do that so in order to do that using Jenkins I have to create a docker file which which the Jenkins will use to build a container image now how do you create a dau cup I'll just type in sudo nano and then the name this is docker file hit enter and what I want to do is I want to download an Apache a container so basically I have a per second cleaner in place which is called web app so I will be downloading that then I will be adding everything which is there in this repository which is dot and I will be putting it inside slash where /ww w / HTML of the container and that is it right let's save it so this is how my docker container will be built so this has to exist on git because this also has to be copied onto my slave so let's stage it let's commit it and I just specify I added docker file right and now let's push it on to a repository Estrela so get push origin master right this is the username this is the password great so now my code has been pushed on to the master which is my taco file has now been pushed on to the repository let's verify that so let's go on to repository and I wants to order you flash over here so as you can see I have a dog a file in place that I've been just added over here now let's go ahead and check on Jenkins to not check basically let's go ahead and configure the build website job in Jenkins okay so now I'll create a one more one more job which is basically build a website build - website it's a freestyle project and this also will have has to happen just on the stadium server right it's okay so it says there's no agent or cloud that matches this assignment all right so it's specify staging right so again it has been did a service by OneNote great do we want to download the core again no we don't wanna more down with the core again and what I want to do is I want to execute some set of commands now what are the commands that I will be executing the first thing that I'll be doing is I will be deleting any container which is running in the machine right so for doing that I'll have to type in the command sudo docker RM - F and then I'll have to delete all the containers for which the command would be sudo docker PS - - cue this will list all the running or dead containers and then it will this particular command will only list the container ID and this will be piped into docker RM - f command which you basically remove them from the system so this is very important because every time this job will be built the earlier containers should be deleted right the next thing that I will be doing is I will be building the file so the file would be in the same place where this particular command is being executed so this come this sorry the docker file would exist inside slash home slash abun - slash Jenkins and then there should be a place over there so I think it would be workspace Jenkins splash workspace and then inside workspace it would be but it would exist in the repository which is basically a website okay so sudo docker build and what we want to name the image is let's say website this is then it would be the name of the container okay so this is where my image will be built and once the image is built I want to run this image so it will be sudo docker run - I T I will do port mapping I want to deploy it on let's say port 82 right so let's deploy it in Poe DP - and now let's specify the name of the image which is website alright so this is what I want to do and that's it that's that's that's basically it's gonna have to apply my website so let's try it out let's click on save right and now I have two jobs when is build website and one is get so let's try running get shop first and let's see if our code is basically copied onto the staging server so I can click on build or manually and just check if it happening so it gives success if it's a blue ball that means it's a success so let's see the logs so it says that the code has been copied so let's check it on our staging server here Emma let's do let me do LS so I have the Jenkins folder over here let's go inside the Jenkins folder slash home slash open to slash hankins that I have something called as workspace let's go inside that and if I do LS I have get job ok so the path that we specified is wrong we will have to specify get job too right let's do an LS ok so here is all my files alright so let me just copy this directory path right and as you can see the files were copied successfully so this job executed successfully we'll just have to check if the other job which is build website that also works perfect right so let's go inside build website let's go to configure and now let's change the path so the path is basically this let's change it put the path which is over here which is basically this great so let's specify the path over here right so in this particular directory I have my dacha file so that will be built and you've been named website let's save it and for this particular job to execute successfully I will have to check if there is a container which is running so let's run a sample container let's sudo docker run - 90 - D and then let's run out of container hold open - right so why am i running a container already is because I have specified that if there is any container which is running on the computer it should delete it and ideally at every trigger on off the job there would be a container which would be running right so I've specified and now if it were a sudo docker PS I can see that there is one container which is running over here great now let's try to run this particular job which is the build website right so let's click on bail now and let's see how it goes so the job is getting executed let's hope it doesn't fail well it should not fail but in cases it does fail so let's see how it goes oh so it gave us a blue icon which basically means the job executed successfully and if it did we should have a website on port 80 - let's check it so control V and then put 80 - are we getting a job oh we are not getting it away here so let's check what basically happened in the build website let's check the log so the container was downloaded successfully the website was added over here it was created the image was created and then they should have been one more okay so yes the container is now running and it's running on port 80 - but I cannot see it over here let's check why is that the case so it says refuse to connect okay let's go to a staging server let me do a pseudo docker PS I can see the website is running actually and it's available on port 80 - and okay I guess I know what the issue is so let me go to instances and let me go to thee okay I think I know what the issue is so I was copying the wrong IP address guys I was copying the Jenkins IP address I'm so sorry yes even Bala is Bala Murugan is also giving me the same flu so sorry guys I copy the wrong IP address my bad so the IP address would be of the staging server which is basically this let's hit enter and yes I'm getting my website over here so awesome guys we are a job executed successfully it's not it's just that it's not executing in a pipeline so let's execute it in a pipeline right and that to automatically so how to do that so this job executed successfully we'll have to go ahead and go to get job which is this we'll have to configure it and now we'll have to basically specify post build action right so once my code is copied successfully I will have to click on add post paid action and now I will have to kill build other projects right and what are the project do I have to build I have to build the the build website project let's hit enter right okay so pear website this is it and we will only trigger it if the build this table right this is what I want to do so let's click on save great so my I have two jobs now I have the good job and I have the build website job ok awesome so these two jobs will have to be executed 6n sequentially so when this job completes successfully it will basically go ahead and it will execute the build website so awesome so now what I can do is I have to basically make my github talk to Jenkins so that whenever there is a change in github it automatically triggers the get job build now the get job job right so in order to do that I'll have to click on settings on github and then I will have to click on their books okay so once I'm inside my books I'll have to click on add my book and in add web book I will have to give the URL so the URL guys would be the same that you have a video which is of Jenkins let's copy it let's paste it here and now after the URL you have to specify github - web hook and then slash right let's click on add my book now so as you can see you get a green tick here which basically means the book has been added successfully that's a good thing now let's do a very quick thing which is pushing on our github website and let's see if it triggers a job and the basically the website should change over here right so let's do it so I have index dot HTML let's go inside index.html right let's change to welcome to and telepods and then let's add the DevOps text right this is a change that I've done let's stage it let's commit it changed website content create and now let's push it on to our server that is our github sorry hit push origin master this is the username this is the password and now my github has been pushed now as you can see there's automatically a build queue has been triggered for my good job and now it is there for build website and once this is empty it should basically okay so it shows no bills in the queue I let me refresh it once yes all the jobs are blue which basically means if I go to my website and if I do a simple refresh over here you can see the text got added automatically right so what what happened I pushed on github it triggered the get job which basically copied the code on to my staging server and then it triggered the build website job which basically deleted the older container built the new container with the new code and then deployed their code the rocker container on the staging server on port 80 - and that's how you see this website let's try this once more guys so let me go to my server let me change the website let's let's do something else now let's let's add one more header over here and let's say creating a CI CD pipeline is now complete right let's close the header let's save the fire and let's stage it let's commit it changed h2 and now let's push it onto github get push origin master this is the username this is the password and now let's wait for some time this should automatically get updated let's just hit refresh let's not go on to Jenkins and let's hit refresh this website should get updated in some time great so now as you can see the website has been updated automatically by just pushing code onto github right and this is exactly what a pipeline is guys so let me go ahead and now let's finish off it and finish this pipeline off by pushing it to production right let's create a new job which is push prod right is a feast trial project and what I have to do is I want to first copy the github code on to my production system right so for that I'd have to specify the URL which is basically this let's specify the project URL and we want to restrict this product a project to just run on production right and basically I am doing the source code bandwidth kit this is the URL what else it need not be triggered by a go to github OOP trigger because this will be triggered by my build website job and in the build steps I'll have to specify the same commands so the commands would be that first I need need to delete any container which is present on the production system so that is darker stalker PS F&A - cue and I have to specify a suit over here right so this will basically delete any container which is running on the machine previously then this will build the container from the strike is a slash home slash open - slash Jenkins slash workspace slash and what the name of this job it's push prod so the directory is push prod and inside the cyclomatic off I will exist and let's name the container as website right now let's run this pseudo vocal run - 90 and I would want to run it on port 80 because this is production right and now let's specify the container U which is basically website great so I've done that and everything seems fine let's click on save awesome now this particular job will be triggered by a build website so let's configure it to trigger it so we they have to add a post production build other projects which product to project to build which is push prod right this project will be built only if the build is stable and now let's click on save great so now as you can see the pushrod job is also ready and let me copy the IP address of the production over here and let's verify nothing is working on this particular IP address as of now all right great nothing is working now on my production let me deploy a new container so sudo doctor run - IIT and - didi let's run a pseudo container let's call it a boon - it will now start great and now let's go ahead and push a job right so we'll open index.html let's change the h2 on production - this is the text that I'm adding let's save the file let's stage it commit it added code for production great and now let's push it onto github gate push origin master let's specify the username password everything is done it should trigger the job so get job is triggered great now build website is triggered great and now push prod will be triggered so let's hope everything goes well over here so this will takes time because it will download the code and then alright so this also completed let's verify if all the jobs completed fine so this job is still in progress let's check the logs what is it doing so yes it gave me a blue sign which basically means success so if i refresh over here great so creating the CI see the pipeline is now complete on production - right and this is the IP address of the production and this is the IP address of staging if you refresh it you get the same code over here as well so great guys we are done with the demo right so we had to create an automated CI CD pipeline and we have done that so we are making changes on github which is triggering the bit job job which is basically downloading the source code on my staging server which in turn is then building the website on the staging server and if everything goes well it is then pushing it to production so with this guys we are done with the session so guys thank you for attending today's session I hope you have learnt something new today now if you are interested to learn DevOps with us we also happen to offer the DevOps course and we also happen to offer teaching you AWS because DevOps and ews goes hand in hand right so if you want some details I can actually show you the website right so you just have to head on to enter the part.com and then you will have to go on to the DevOps architect course so it's basically called the cloud and abouts accurate course so she is Kumar is saying can you share this session so she leash my team will get in touch with you for that right cloud and what she's the session is also available on YouTube so basically you can check it from there as well so just search for cloud architect and once you have sourced it you will get the courses just go on cloud and divorce architect masters course right and this is a post guy so basically we teach AWS Microsoft Azure DevOps Python Google cloud this is a part of our online training course right so this we teach you because all of these are expected from a DevOps engineer all right so just we will be teaching and there are a host of other things which again is a good to know kind of thing so that we have added as a self-paced thing in our course right so as part of the promotion if you guys are attending this session you are eligible for 30% discounts all you have to do is just go onto this website you can also call us on these numbers if you are in the US you can just go to this number if you are in India you can go onto this number and you can call us up the promo code is YouTube 30 guys you can use it on the website and you'll get a 30 percent discount on the whatever price is being shown on the website at that time so this particular price is the lowest right now so if you go ahead and buy this cos right now you will get a 30 percent discount in this price and you would be able to take this course so guys this teaches you all this course and then it also gives you a capstone project which would be a combination of all these technologies and we guarantee you once you're done with this course you will be basically equivalent to a six months experience DevOps engineer that is a guarantee that Intel about gives you okay so guys if you're interested just call on these numbers and we would be happy to assist you so with that guys I would like to take a leave from you have a great day ahead and good bye and if you have any doubts please comment it down in the youtube comment box and we will reply it at the earliest have a greater ahead and go bad guys
Info
Channel: Intellipaat
Views: 55,066
Rating: 4.8347936 out of 5
Keywords: CI CD Pipeline Using Jenkins, Continuous Integration and Deployment, continuous integration, jenkins tutorial for beginners, ci/cd devops, ci cd pipeline Jenkins, ci cd pipeline demo, jenkins, ci cd pipeline jenkins tutorial, ci cd pipeline jenkins docker, ci /cd pipeline Jenkins, ci cd Jenkins, ci cd tools, ci /cd pipeline diagram, continuous integration and deployment, Intellipaat, Continuous Integration, Continuous Delivery, intellipaat, edureka devops intellipaat devops
Id: PXq2OsdxkqU
Channel Id: undefined
Length: 82min 9sec (4929 seconds)
Published: Thu Sep 19 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.