CICD using Jenkins Pipeline and Pivotal Cloud Foundry | DevOps | Tech Primers

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in the last Jenkins pipeline video we saw how to build our codebase how to test it as well however we never saw how to deploy the same artifact into a cloud instance in this video we are going to see how to deploy using Jenkins pipeline in two pivotal cloud foundry instance thank you very much Rashmi for providing the pivotal cloud foundry login I had already mentioned that I had lost my trial version of the login for the pivotal Cloud Foundry because I had created it long back and it got expired I got the new login from rush me who had added me as a member so I am able to access the instance which she has so I'm sharing that instance with her thank you for that Rashmi so I will be showing you how you can deploy into this particular Cloud Foundry instance using Jenkins I'm not going to follow any manual process let's use the Jenkins pipeline to build our code base which is hosted in github and then push it to the pivotal Cloud Foundry instance let's get started [Music] let's the bell icon on the YouTube app and never miss any update from tech famously we are going to create the code and host it in github I'm going to use the spring initializer started spring dot IO in order to create a spring boat application and then push it into the github repository and the moment you push the code or commit the code we need to push it into the little cloud foundry instance basically the moment you commit code into the github code base or the repository it needs to be pushed into our development environment right that's the ideal case of a continuous integration and continuous deployment pattern we already saw this kind of pattern using AWS code pipeline in this video we are going to see using Jenkins pipeline and we are going to push it into the pivotal Web Services or the pivotal flower foundry so in order to do that we need to check out the code from github and we need to build that particular code basically we need to package the source code into an artifact which can be shipped into the destination machine so in our case we are going to use the spring bootie application so we need to build the jar out of it so we can skip the test stage because I'm going to show you how to deploy it so after the test comes the deploy so that this is the ideal case of a Jenkins pipeline so we check out the code build the code usually you run unit tests or functional tests over that particular code and then we finally reply to the dev instance and from there we can take on and apply to the other instances for example situ a TN production so let's go to the spring initializer and create a spring boot application so I'm going to name this as comm tech primer slash Jenkins I'm going to call this particular artifact as C icd-10 Keynes example so this is going to be a continuous integration and continuous deployment example so what endpoints do we need we are going to use the spring MVC so let's add spring MVC I'm not going to add anything else I'm just going to add the spring MVC dependency to it I'll open this project in IntelliJ the project is now open in IntelliJ and I can see only the main class which is the CIC the example pipeline example application right so let's add one rest endpoint just for the sake of testing it so I'm going to call it as a Hello controller and this is the rest controller so I'm just going on annotate with the rest controller and let's add a get mapping which is going to return us hello YouTube that's it I don't have anything else in this particular project now we need to add the Jenkins file to this particular project so I've added the Jenkins file into the roux directory because that is the Jenkins file which is used by the Jenkins pipeline in order to build its pipeline we need to have the dsls in place so the pipeline is the first DSL in since this Jenkins instance is going to be running in my machine I don't have any specific agents so I am going to say run and use any agent and we are going to define different stages in it so there are different stages the first stage is the build stage because as a part of the pipeline I'm going to build and then deploy it I'm not going to test it because I don't have any test case in this particular code base but I'm just going to deploy the application after building it so I have only two stages the build stage and the deploy stage and as a part of the build stage we are going to compile the code base and we are going to create a package out of it so there are different steps we need to run right so the maven clean package is one of them so let's create some steps so steps is another DSL you know to create a pipeline stage I'm going to use the maven option so using maven 3.5 dot 0 which is configured in my system I'm gonna run the maven clean package so in order to package the artifact I'm gonna run this particular code base with maven clean package and the next stage will be the deployment stage as a part of the deployment stage I need to run again some set of commands right so these are the commands which are used to deploy into my PCF instance if you see here this deploy stage is the final stage right so I need to deploy my artifacts into PCF in order to do that I'm gonna use the width credentials plug-in and retrieve the username and password from my Jenkins instance so I am going to configure my username and password in Jenkins so if you see here this with credentials is a DSL which is going to retrieve my username and password for the PC of login so this is this is the credential ID which I have created PCF login is a credential ID I'll just show you by logging into the Jenkins instance so indigent Keens instance there are something called credentials if you have known this is the credential store and I have added my PCF username and password here see that this is my PCF username and password there I have given my ID name as PCF underscore login and I have given my username and password here this is nothing but the description so this is what I have given here I'm going to use this username and password at the run time here so what Jenkins will do is using the with credentials it will go and retrieve the username and password and store it in the variable called username and password and we can use that username and password here see that this is the CF CLI command if you are using Cloud Foundry you know that this is how you log into the cloud foundry instance and that's what I have done here and next I'm gonna run the CF push so if you have the CLI installed directly on your Jenkins machine you can use the CF directly but I have what installed in the shared location in my local so that is why I had to use this inside the Jenkins machine so I'm just doing a see of you log in this CF login will log into the API the command-line interface will log into the API of my pivotal Cloud Foundry instance and I'm going to use these CF push command in order to push the application in order to push the application beneath the manifest file the CF CLI requires the manifest file so I'm going to create the manifest yeah Mel this manifest yeah Mel will have the details of the application configuration for my application so I'm going to have applications and the name of the application can be CI CD example CI CI jenkins example let's call it that way right and the number of instances I want is 1 the memory which we require is like let's give 800 MB the path of my artifact is what I need to give here so the artifact path would be something like this right and I need to give the name of the jar here so what will be the name of the jar it will be 0 dot 0 dot 1 with this particular jar example so let's cue the artifact 0 dot 0 dot 1 - snapshot jar so this will be the artifact name so I'm giving the path of my artifact as well as a part of the manifest file so when we run the see of push here as a part of the Jenkins pipeline here the manifest file will be leveraged to push the application on to Cloud Foundry instance so that is what we are doing here so now we need to push this into github so in order to do that I'm going to log in to my github instance and create a new repository and I'm going to push this particular change into that new repository so I'm going to call it the same Jenkins example say a CD Jenkins example so I will copy the remote command and I'm gonna initiate a get for this particular project so let's do get let's do get in it this will initiate get in this particular project and I'm gonna link the remote repository into this particular project again now we can add the files and we can commit them that's it so we are done we are going to push this into the master so the moment we push this should be in github yep the cord is all pushed into github there's no read me right now I'll add the readme after the recording is completed and you can take a look at the readme to understand what are the steps which we have performed see that we have the Jenkins file and everything is sorted however we do not configure the github project in our Jenkins instance so the build won't trigger until we configure it right so I'm going to create a new project and I'm going to create a multi branch pipeline so let's call this a CI CD Jenkins example and let's create a multi branch pipeline so there is an ad sources option here I have a option to select github and I can select the credential so I already have the github credentials uploaded here which is tech primers and slash whatever and so the repository which I'm going to use is the CIC Lee Jenkins example yeah this is the repository which we want to link so using the tech primers login we retrieved all the repositories and I'm going to link the CIC Lee Jenkins example the build configuration says by Jenkins file yes we want the Jenkins find if let's say you don't have the Jenkins file you want to have the configuration inside the Jenkins instance then you can paste it here so there will be a space here if I don't have the Jenkins finally you can paste the script here right that's it I don't have to set anything else so let me save this configuration the moment I say save this configuration the build will be triggered because the scans are going to be triggered and it is going to look into the Jenkins file if it is having a Jenkins file immediately the build will be triggered on each of the branches which has the tenant kins file so we have only the master branch so we can see the master branch getting built notice that already the build stage has got triggered if I compare the Jenkins file I have here so we have two stages build and then deploy directly that's it you're not doing anything else so let's look at the logs what's happening as a product build so as a part of the bill the maven 3.50 version got picked which is what we had configured it has picked that particular version and then the maven package has got triggered and it is getting wrong see that the maven clean package whatever come on we had mentioned here it was wrong and the build is proceeding so let's wait for the build to succeed and let's proceed to the deploy stage so finally the build stage got completed and the the Prostate got kicked in as a part of the deploy stage the CF log Ennis will be triggered on the CF push is going to happen let's look at the log now because this is the final stage let's go to the end yep the sea of push is happening if you notice your the CF login come on got triggered see this is what we had given right the username and password if you see has been masked because Jenkins masks this because we retrieve the username and password as a part of the with credentials plugin so we have successfully logged into the API and finally the CF push command got triggered so when the CF push command got triggered the manifest file was leveraged and the artifacts are getting uploaded and in fact we should be able to see the name of the application here yep see that the last push was few seconds ago this is the application which we deployed CI CD Jenkins example see that this is what is getting pushed right now let's look at the logs inside the Jenkins file to see if it is all good yep the build is successful I guess yep the build is successful I can see that blue option here so the build and deploy got successful and let's hit the endpoint and see if the application is up yeah the Springwood application is up we had added a endpoint called hello and that also says hello YouTube so this is how you can use Jenkins pipeline to trigger the build just to check again the configuration what we can do is we can update the hello controller to hello take primers and let's try pushing this change again and meanwhile I will summarize what did we do as a part of this particular video so what I will do is I will just push the change to the remote repository since I don't have the hook setup right now I think there won't be automatic trigger so I'm going to do the build no option so I'll just summarize what did we do as a part of this particular video so we created a Springwood application using star dot spring dot IO the spring initializer we added a hello controller a dummy controller just to check our feature in this particular application we created the Jenkins file with two different stages the build stage and the deploy stage in the deploy stage we added the width chills DSL is basically a plug-in called with credentials which you need to install in Jenkins and after the installation of that you should be able to use this particular DSL so this is to retrieve the password and the username at runtime because we don't want to hard code the username and password in this particular Jenkins file in order to do that Jenkins provides this credential store where you go to the Jenkins instance add the credentials in the Jenkins instance and from the Jenkins instance you can retrieve it using the credential ID which you have given so I have given the credential ideas PCF underscore login the username and password is retrieved from there and using the sea of CLI the Cloud Foundry CLI we are logging into the API URL using the username and password and we are doing a sea of push because by default I have the manifest or Tamil in this particular root directory so if you have the manifest Yama in a different path you can mention CF push - F and then the path of that particular yeah Mel file also we came to Jenkins and we created a multi branch pipeline project this is because if you want to how builds per branch you can do that for example if let's say I'm going to create a new branch let's try doing it I'm going to create a new branch called feature test and I'm going to push this particular feature branch so if I push this particular feature man's to my remote branch to my remote repository there will be a new branch it should be created and the build should be automatically triggered since I don't have the hook enabled it won't be automatic but when I trigger the scan repository now it's going to scan my repository and automatically create new pipelines based on all my branches so here right now only the master branch is there see that the feature branch also got kicked in because we had pushed a new feature called feature - test and that also got kicked in and it also is trying to deploy right so I'm gonna stop this feature branch I don't want to mess up with my laptop I already have less memory in it so I don't want to mess it up so I killed the feature branch let's go to the master and see if the build is successful now the build is going to take another oh it's already deployed right yeah I think the hook or the scan no option triggered the build again but the deploy got succeeded let's go to the URL and hit it should say hello tech primers yeah we got the hello tech primers so this is how you can enable the continuous integration and the continuous delivery as a part of Jenkins pipeline and you can be crazy with the Jenkins pipeline you can add multiple stages you can have stages for scanning you can have stages for sonar bill you can have stages for running your test suit you can have even a stage for validating after it is deployed so you can have multiple stages in your pipeline and have it integrated into your Jenkins pipeline since the Jenkins find results in your repository it acts as a version control as well so you can control the whole deployment process from your codebase itself as a part of your source code I hope you were able to understand how to configure a Jenkins pipeline and how you can leverage continuous integration and continuous delivery to push our artifact from github into pivotal cloud foundry instance as always if you liked the video go ahead and like it if you haven't subscribed to the channel go ahead and subscribe to it meet you again in the next video thank you very much [Music]
Info
Channel: Tech Primers
Views: 20,924
Rating: 4.9463086 out of 5
Keywords: techprimers, tech primers, pivotal cloud foundry deployment, cicd using jenkins, jenkins pipeline example, cicd jenkins pipeline, jenkins cloud foundry deployment, cicd example, jenkins pipeline usage, cicd tutorial, jenkins pipeline tutorial, continuous deployment, continuous integration, ci cd in jenkins pcf, pivotal web services, cicd using cf cli, cf cli usage, cloud foundry cli in jenkins, continuous integration and continuous deployment using jenkins pipeline
Id: 1fPTOhn8fgk
Channel Id: undefined
Length: 19min 15sec (1155 seconds)
Published: Mon Mar 25 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.