DevOps Project | Creating CI CD Pipeline Using Jenkins | Intellipaat

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome back to intel parts devops week and in this particular day we're going to look into a devops project which is an end-to-end automated pipeline so the previous session we looked into nexus repository and now we're going to look into a complete project because this is the last day of the devops week which is day 11. now before moving on let's look at the agenda we'll start off with what is devops what is the ci cd pipeline and then look into the devops tools that is the devops tools which we have covered and some more devops tools to understand the basics and once we get to know all of those devops tools finally we'll be creating an end-to-end automated pipeline in the aws cloud using multiple devops tools so that would be the last part of this particular session so before moving on with the session please subscribe to our channel and also hit the bell icon for the upcoming updates from our channel and also if you enjoy our content you can leave a like 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 theme where you basically build the code you create all the tools that you need right and then you deploy it on the server and for deploying it on the server the 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 onto production right so this is a very general way of saying that how an application is basically deployed onto a particular server right now earlier when devops was not there everything was done manually so developer used to be done with his work 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 it used to work they were used to push it for testing and when testing was done events everything was done they used to push it to the main server from where their application was basically hosted now this it 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 softwares are not installed in your ops machine it could be that the ops machine guy is basically using some other version of the software etc 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 development process so we had to solve this and for solving this we came up with devops now what does devops say 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 your code onto that tool it will automatically be tested it will automatically be deployed onto 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 uh 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 he used to commit his code onto a version control system right now what is that version control system that version control system is nothing but it could be a github it could be bitbucket it could be anything right so the developer used to push his code onto a version control system and what happens is the continuous integration tool basically used to see if there's any change on the version control system if there is any change it automatically used to detect it and to use to pull the code from the version control system and deploy it on the testing server okay on the testing server you used to have you know you have 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 deployed 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're 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 i mean 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 kci tool which again used to be pushed onto the testing server testing used to happen and if the testing succeeded it used to be pushed onto the production server so this is basically a very minified version of how a devops life cycle basically works right and the heart of this life cycle is the continuous integration tool which basically takes care of uh 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 uh 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 onto 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 tool the magic tool that we were discussing what is that tool that tool is nothing but jenkins so what is jenkins in the most easy terms it is nothing but an open source automation server which is basically based on java and it helps to automate tasks which are related to uh devops right so basically it makes way for the code from one life cycle stage of devops 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 adoption you have something called as plugin 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 they are around so what 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 installations which are basically happening throughout the world and are basically working with jenkins installed on so basically there are one lakh 47 000 servers which have jenkins installed on them all right uh when you talk about the plug-in support so jenkins constantly get a lot of plug-ins uh 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 it has around thousand plug-ins which are currently available in the jenkins repository on which you can install plugins and you can get the work done all right 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 for jenkins which does nothing but it extensifies the use of jenkins it extensifies the features of jenkins now let's move ahead and understand how we can set up jenkins right so we'll have to set up jenkins on aws so these would be the steps for it the first thing that we'd be doing is we'll be launching an aws 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 um so just give me one second and i'll open the browser and now let's head on to our aws website all right now let's sign in to our aws management console so uh once you sign in onto your wrist management console so guys if you don't have an aws account you can just click over here and create an aws account for you there are a lot of documentation available online you can head over to intellipa.com blog and there is a blog called aws 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 your account ready you can just log in with your email id and then your password all right so what we need is an easy two instance so we'll click on the ec2 service and basically we would be needing three servers uh we would be needing uh two servers 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 onto the main server which will be our production server so the servers that we'll be launching would be ubuntu servers guys so let's select the ubuntu server the processor that we want is t2.micro let's select that the number of machines that i want would be three right now let's go ahead and click on review and launch right now let's click on the launch button and now let's select the uh let's let's create a key pair and let's choose that key pair so let's say the key pair is jenkins right let's download it so we have a key pair downloaded and now let's click on launch instances all right so i have three servers set up um so the first server would be now let's see this is my jenkins server right and now let's set up the other two servers which are basically the staging server and then we have the production server all right okay guys cool so now we have three servers which are set up right and these servers are ready to be connected to right it might take some time it might take like a minute or so to get deployed so the movement it is deployed uh we will try to connect to it all right so let's try on by connecting 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 the putty tool guys you'll have to specify the ip address over here of the server that we are basically connecting to and then we'll have to basically uh select ssh and then auth and then we'll have to select the key pair through which we want to connect now the key pair over here guys it basically is for the ppk format uh so shirish kumar is asking me can we use same key for three servers yes siri so i'm actually using uh the same key for all the servers which is basically the jenkins.pam file okay so uh this pen file what i'll be doing is i would be first need uh needing to convert it into a ppk file the reason for that is that uh putty it only accepts a ppk file now how do you convert it into ppk file is we have a putty gen 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 uh jenkins stockpim 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 a passphrase so i'll have to click on yes and now let's name the file uh 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 is uh you'll have to go to ssh and then you'll have to click on auth and then you'll have to select the ppk that you want to connect to now the ppk that i want to connect to is jenkins.ppk here it is now i'll click on open and this will basically give me a 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 uh you know that i have used is ubuntu the username through which i'll be connecting would also be ubuntu all right so as you can see i'm logged in to the server 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 apt-get and then update right so this will start off by updating the machine so the updating is almost complete uh we'll also have to install uh jenkins guys 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 jlp protocol basically requires java so we would be using java to connect jenkins and the slave machine so first let's install 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 our 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 all right and now let's open uh 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 our staging server is now yellow and now we would be connected to it great now let's update the machine so sudo apt-get update that should update the machine and while this is updating uh 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 great 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 an xml is the next one would be to download the jenkins package so let's do that let's download the jenkins package all right it says um not downloaded no issues we can actually download it all right um let's let's look at the documentation for installing jenkins there could be that i've missed out on some commands so installing junkins on ubuntu 18.04 now i personally refer the digitalocean uh documentation guys because it's pretty simple and it works most of the time right so we are on this step so wget 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 on ubuntu 18.04 let's try with this documentation so openjdk is something that we have 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 uh so let me give it to the people on go to webinar so that they can also use it so guys uh for this key just use this particular command all right so i have given so now i have the key imported now let's go ahead and go on to our 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 repositories 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 while it's getting installed all right my staging server jenkins um the java has completed installing uh let's similarly connect to our uh production system as well and let's install java on that so this is the ip address let's connect to putty give the ip address over here give the auth file which is basically jenkins dot ppk this and now let's hit on open uh 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 the color as orange let's click on apply just a quick info guys intelpad provides devops online training validated and certified by nasscom future skills and ibm the course link is given in the description below now let's continue with the session 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'll ask for us our confirmation we'll give yes and now java is now being installed on my production server also let's see if junk installation 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 it's installation over here we'll start the jenkins service and then we'll try to connect to it all right so as you can see jenkins we have got the dollar prompt back 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 nothing goes wrong i think it should work well uh 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'll 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 along 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 have not opened the firewall of my systems to basically allow port 8080 so let's do that so in my aws servers i'll 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 ports 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 go to port 8080 it should give back me a page right now this page will basically give me an auth or it will basically be an auth page where i'll have to see uh there'll be a path over here and i'll have 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 path so i'll have to basically echo whatever password i get over here and i have to enter it over here right so let's go ahead and do that so i will be putting in uh cat and then the path uh it 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 to install plugins so what i do is i would go ahead with install suggested plugins and this would 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 the installation process is complete we will go ahead and start adding nodes to jenkins so that we can basically create a pipeline out of it okay so let's wait for jenkins to be installed and meanwhile let's head on to our ppts okay so we have executed uh we had launched in aws instances we connected through ssh and we have executed the 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 [Music] the outside so guys 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 devops and jenkins basically has its software installed on one machine and what you do is you connect the jenkins master to the testing server and to 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 so 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 uh let's just wait for a minute so for it to be complete and let's then add nodes okay so for managing nodes in the enkins 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 the jnlp protocol what you'll have to enable is you'll have to enable uh you have to basically open all the ports between the servers uh 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 on which i just edited the inbound rules and that firewall can basically be used to basically add further rules let's do that so let me go to the browser and let me go to the security groups of my aws servers 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 ports let's do all traffic uh 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 the other slave nodes that they have launched they are in some other security group right so you can also specify only the security group over here that would also work but since we are just practicing it and we just want to look as to how devops 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 and let's head back to our slides and let's try to uh basically see let's if if our jenkins is now ready with its plugins yes so jenkins has installed the necessary plugins uh now because this is the first time we are setting up jenkins will ask me the username so let's set up a set up the username let's give it my name and 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 teleport 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 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 we want to do is we want to manage nodes right so let's click on manage jenkins just a quick info guys test your knowledge of devops by answering this question what does devops stands for a development and operations b drive and operations c digital and operations d none of these comment your answer in the comment section below subscribe to intellipack to know the right answer now let's continue with the session and once you have clicked on manage jenkins let's go ahead and check all the options which are available over there right so let's click on configure uh global security right so this is the first setting that you have to do just 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 nodes okay so let's wait for it to 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 for for inbound agents so the value has to be random over here so we'll be we it can pick up any random tcp port and through it 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 nodes so there's one more option over here which is manageable let's click on that so the only node that we have as of now is the master which or this is basically where my jenkins is installed right now let's click on a new node and let's try to add 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 all right great so now you would get a screen which would look something like this so first you'll have to specify the remote root directory let's specify it to be slash home slash ubuntu slash jenkins all right great uh then we'll have to specify the launch method so the launch meter has to be launch agent by connecting it to the master okay 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 it'll 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 new node again and now what i want to do is i want to click on basically i want a production server again click on permanent agent click on ok and then select the same options again so i want the remote root directory to be slash home slash ubuntu slash jenkins and the method would be launch agent by connecting it to the master and finally we'll click on save so now i have two nodes which are basically giving me a cross because they are not connected as us 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 to connect to the master right but there are two files that you'll have to download one is this file slave agent.jnlp that you'll have to download from the jenkins tool over here and then the next is the agent.jar file right so let's go ahead and download it so let's click on launch this will download the jnlp file right and now let's click on agent.jar this will also download the agent.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's a tool which is basically called filezilla this is basically a ftp tool which you can use to copy uh data from your local system onto the server okay 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 username is ubuntu 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 ppk 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 this server and for that i'll have to just do a drag and drop into filezilla and this would basically copy the file so the first file was agent.shar you'll get a notification which will go something like this and now now i have to do a slave agent dot jnlb i have to transfer it on the server that file 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 uh these files will have to be renamed so let's do that so mv and then agent char this i will have to change the name to agent agent.jar oh sorry my bad so i've basically given comma it has to be agent dot char all right so if i do my ls now agent.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 slave hyphen agent dot jnlp this is just because guys while i was downloading it i already had an agent.jar file 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 ctrl c and now let's enter the command right so as you can see it says connected which basically means my agent is now connected to my jenkins server so staging server is now ready you can see that i am seeing the free disk space i am 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 productions ip address is basically this let's copy it let's connect it through filezilla and then we'll transfer the files onto the files here so it says connection failed okay they failed because i'm not specified the port let's hit quick connect again all right so now i have the directories which are on the server let's copy agent3.jar onto the server similarly let's also copy slave agent.jar over here all right so all the files have been transferred now let's hold head over into our production server which is in orange let's hit ls and i can see that there are the two files that i just copied right let's rename them so mv agent and i have to rename it as agent dot shar done similarly let's rename the slave file as well so i would be renaming it as slave hyphen agent dot jnrp 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 both production and staging are now ready okay so the metrics are not showing up uh 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 servers awesome now let's go ahead and let's start by creating our pipeline so what we'll be doing is let's create a new item and what we'll be doing is we'll be doing a freestyle project let's name this project as uh so basically we'd be doing three jobs guys in jenkins let me show it to you on the ppt so basically what we would be doing is we would be using get and we would be using docker right in the pipeline today so what would the git and docker be doing so basically uh git would have have a code of one website that we will be creating a very uh random website that we will be creating and that website will basically exist in git 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 all right we understood that we want to use git and docker but how do we do it let's understand it using the ci cd 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'll have to pull the code from git and once we have pulled the code from git we will have to deploy it on uh using a docker file we will have to deploy it inside the docker 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 you'll do is we'll also push the code onto 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 have to pull from git 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 uh 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 execute 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 which you can test it's an application which is finished for testing and then there could be a production pipeline that you have created so that means you know your application has been 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 done all right now let's go ahead and see what are the things that we would be doing so guys we would be creating three jobs the first job will basically download the git 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 uh or building the code onto a docker container or wrapping the code 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 steering server and everything goes well it will then invoke the push to production job which will do nothing but it will also download the code on the 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 now so first job that we have to create is the git shop so let's specify that git hyphen job and now let's click on ok just a quick info guys intelpad provides devops online training validated and certified by nasscom future skills and ibm the course link is given in the description below now let's continue with the session all right so this job will basically pull code from a particular github repository 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 um so i have a github account guys you can also create your own github account it's free and then you can upload your code over there right so let's create a new repository over here let's create a repository which is called the website all right and now let's click on create repository great so i have a repository in place now which is website dot kit uh 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 a 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 uh create the website right so first we'll have to do uh create an index file let's say the index file goes 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 of the webpage the body would have one header and the header would go like welcome to intellipart right let's close the header and now let's close the body too finally let's also close the html and now let's save the file okay so the file has been saved what we'd be doing is we'd be initializing a git repo here then we would be adding our github repository where we will be basically pushing the code 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 so the file has been committed and now let's push it on to our github so get push origin master it'll ask for the username let's enter that it'll ask for the password let's enter that and now your 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 closed body and then the closed html great so now i have my website on this particular git repository so what i'll be doing is uh i'll 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 git job so the first thing that i want to do is i would be selecting the source code manage option which is basically git and the url is this this is where i want to download from okay is there any particular branch so i have committed my code onto master so this that is how we would be working on uh is there any build 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 will only do it on the staging node this code will be downloaded on the steering node this is the github that i've specified the master will be built it will be built using github hook trigger and that is it that is all i want to do right so let's click on save great so now what i've done is i have created the git job which i had to do let's come back to the slides so the git job is now complete it downloads the git 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 okay for that i would need docker to be installed on this particular machine so let's duplicate a session for this machine and let's install docker onto it okay so what i'll do is i'll type in sudo apt-get install docker dot io right so this would install docker on the staging machine let's do the same on the production machine as well let's install docker so production machine is 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 docker dot io all right so docker is being installed on this server also okay so on this machine docker is installed let's check so sudo docker ps yes docker is installed just check on our slave machine 2 on our production machine whether we have docker installed so yes docker is installed over here too great guys so docker is installed on both the staves now let's go ahead and go ahead on to our get repository right so i just have index.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'll have to create a docker file which the jenkins will use to build a container image now how do you create a docker file just type in sudo nano and then the name which is dockerfile hit enter and what i want to do is i want to download an apache container so basically i have an apache container 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 would be putting it inside slash slash www slash 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'll just specify added docker file right and now let's push it onto our repository as well so get push origin master right this is the username this is the password great so now my code has been pushed onto the master which is my docker file has now been pushed onto the repository uh let's verify that so let's go on to our repository and now let's do a refresh over here so as you can see i have a docker 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 one more and more job which is basically build a website build hyphen website it's a freestyle project and this also has to happen just on the staging server right uh it okay so it says there's no agent or cloud that matches this assignment all right so let's specify staging right so again it has been it is serviced by onenote great do we want to download the code again no we don't want to download the code 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 so 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 hyphen f and then i'll have to delete all the containers for which the command would be sudo docker ps hyphen a and then hyphen q 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 hyphen f command which will 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 comma this this sorry the docker file would exist inside slash home [Music] slash ubuntu 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 uh in the repository which is basically website okay so sudo docker build and what we want to name the image is let's say uh website this is that 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 hyphen id um i will do port mapping i want to deploy it on let's say port 82 right so let's deploy it in port ep 2 and now let's specify the name of the image which is website all right so this is what i want to do and that's it that's that's that's basically is gonna deploy my website so let's try it out let's click on save right and now i have two jobs one is build website and one is git job let's try running git shop first and let's see if our code is basically copied onto the staging server so i can click on build now manually and i can 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 i'm at let's do let me do ls so i have the jenkins folder over here let's go inside the jenkins folder uh slash home slash ubuntu jenkins then i have something called as workspace let's go inside that and if i do ls i have git job okay so the path that we specified is wrong we'll have to specify git job to right let's do an ls okay so here is all my files all right so let me just copy this directory path right and as you can see the files were copied successfully so this job executed successfully uh we 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 with the path which is over here which is basically this right so let's specify the path over here right so in this particular directory i have my docker file so that will be built and it'll be 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 hyphen id hyphen d and then let's run a container called ubuntu right so why do why am i running a container uh 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 the of the job there would be a container which would be running right so i have specified and now if i do 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 all right so let's click on bill 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 82 let's check so control v and then port 82 are we getting a job oh we are not getting it over here so let's check what basically happened in the build website uh 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 there should have been one more okay so yes the container is now running and it's running on port 82 but i cannot see it over here let's check why is that the case so uh it says refuse to connect okay let's go to our storaging server let me do a sudo docker ps i can see the website is running actually and it's available on port 82 and okay i guess i know what the issue is so let me go to instances and let me go to the 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 uh yes even bala is bala morgan is also giving me the same clue so sorry guys i copied 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 our 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 too automatically so how to do that uh so this job executed successfully we'll have to go ahead and go to our git 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 build action and now i will have to click on build other projects right and what other project do i have to build i have to build the uh the build website project let's hit enter right okay so bell website this is it and we will only trigger it if the build is stable 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 okay awesome so these two jobs will have to be executed sequentially so when this job completes successfully it will basically go ahead and it will execute the build website job 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 on github it automatically triggers the git job uh build or the git 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 the books okay so once i'm inside web books i'll have to click on add web book and in adware book i'll have to give the url so the url guys would be the same that you have over here which is of jenkins let's copy it let's paste it here and now after the url you will have to specify github hyphen web hook and then slash right let's click on add web book now so as you can see you get a green tick here which basically means the web hook 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.html let's go inside index.html right let's change to welcome to intel apart and then let's add the devops text right this is the change that i've done let's stage it let's commit it changed website content great and now let's push it on to our server that is our github sorry get 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 git job and now it is there for build website and once this is empty it should basically okay so it says no builds 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 basically happened i pushed on github it triggered the get job which basically copied the code onto 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 the code the docker container on the staging server on port 82 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 uh let's let's do something else now let's let's add one more header over here and let's say creating a cicd pipeline is now complete right let's close the header let's save the file and let's stage it let's commit it changed h2 and now let's push it on to 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 so let's create a new job which is push broad right is a feast trial project and what i have to do is i want to first copy the github code onto 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'm doing the source code bandwidth kit this is the url uh what else it need not be triggered by a github hoop trigger because uh 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 docker rms docker ps fna hyphen q and i have to specify sudo over here right so this will basically delete every any container which is running on the machine previously then this will build the container from this directory so slash home slash ubuntu slash jenkins slash workspace slash and what is the name of this job it's push prod so the directory is push broad and inside this directory my docker file will exist and let's name the container as website right now let's run this sudo docker run iphone it and i would want to run it on port 80 because this is production right and now let's specify the container name 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 build website so let's configure it to trigger it so we have to add a post build action build other projects which production project to build which is push broad 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 push prod 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 um a new container so sudo docker run hyphen id and hyphen d let's run a sudo container let's call it ubuntu it'll now start great and now let's go ahead and push a job right so we'll open index.html um let's change the edge to onproduction to 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 get push origin master let's specify the [Music] username password everything is done it should trigger the job so git 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 all right 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 a cicd pipeline is now complete on production too right and this is the ib 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 git job uh 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 just a quick info guys intelpad provides devops online training validated and certified by nasscom future skills and ibm the course link is given in the description below okay guys we've come to the end of this session i hope this session was helpful and informative for you if you have any queries leave a comment down below thanks for watching you
Info
Channel: Intellipaat
Views: 5,844
Rating: 4.9269404 out of 5
Keywords: DevOps Project, 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, Intellipaat, devops intellipaat devops, jenkins pipeline tutorial, devops project, ci cd pipeline using jenkins, intellipaat
Id: 7lazzvm1ljo
Channel Id: undefined
Length: 76min 55sec (4615 seconds)
Published: Sat May 22 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.