How to create Jenkins Pipeline with an Example | Pipeline as Code | Tech Primers

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] welcome to tech primers in this video we're going to see how to create a pipeline inside Jenkins so in the previous video we saw about Jenkins on how we can create a maven project in Jenkins on how we can trigger the pulled right so in this video we're going to see how to create a pipeline and what is this pipeline all about so pipeline is basically like a plug-in inside Jenkins so if you had work with Jenkins right so there are lots of plugins so you can install plug-ins and then you can play around with the plug it but pipeline is something like you can create a workflow inside a Jenkins build so it is something similar to a new job or something but it you can control that using jenkins file which you can have it in your codebase and you can control the workflow based on decode revision so basically you can control the whole jobs workflow based on your code so you can have a different build based on your branch you can do so many things in that so basically this jenkins file is a readout of this groovy dsl so you can do lots of things with that so for example this is how jenkins file looks like so you have a pipeline you have a agent so we define an agent we have different stages in the pipeline so you can define your own stage so basically we can define our own stage we can give a different name and we can do whatever steps we want inside ok so this is what we are going to do now so I'll take the same project which we had the Jenkins example like the Ju notify example so what I'm going to do is I'm going to create a Jenkins file so as a part of your codebase you have to create this Jenkins file and the file name will will be Jenkins file so this is how you have to create the file inside your Co Bay so that Jenkins pipeline can identify that ok at this particular code base is the pipeline enabled one ok so what I am doing is I'm just creating a pipeline we just say the agent is any what and then I have different stages right and the first stages let's say I'm going to call this compiled stage okay I'm just going to give up give my own name so that we can differentiate with what we did also here since I have maven project so I'm going to give what is the version of maven which we are using what is the configuration of maven which we are using right so the name of the maven is if let's say I go to the Jenkins build Jenkins actually I go to manage Jenkins global tool configuration so I have the name of the consecration of the maven build maven configuration which I have done there so maybe an installation so this is the name I need to give so that in the build it can use that particular maven because we are going to you do something with made right and this is going to be a step right so I'm going to say steps so if you notice here in the pipeline so that is I would say steps let's all they say steps and inside the steps and however maven we just move this inside ok so inside that I will put a command Sh maven clean compile let's say I'm going to just compile it so as a part of the compiled stream this go and say may even clean compile and I don't have anything else so in the next stage I want to do testing stage let's say right so same way as this copy the same step right instead of maven clean compiler the same way one test okay finally let's say I want to do a deploy so I'll just say deployment stage right so I'm in this case I'm going to just apply to the maven artifact so I'm not going to deploy to any repository as such but I'm just gonna run maven deploy that is going to deploy my code entities repository okay maven repository which a we saw in the previous example right so the my pipeline is set so let's commit this particular pipeline so this particular code is there in the github so I am going to push this code to github and we are going to use the same repository to configure that in the Jenkins job and pull the data from the github and then we are going to build so let me create a new Jenkins job so at this particular stage so I'm going to say a pipeline Jenkins example okay so if you notice previously created the maven project now we are going to create a pipeline okay you can create multi branch pipeline if you want to together built on different branches but I am going to use pipeline because we are going to use only one branch which is the master okay and the github repository is Genting example right yeah so this is the github repository I'm just going to use this to configure it here so here if you notice you have an option called pipeline and you can create the pipeline script here so if you notice here it just says it has a hello world get her plus may be automatically these are pre-built pipelines which you can use but I am going to use the Jenkins file so I am going to say pipeline script from AC and I am just saying that use the gen kids why okay an SCM is nothing but good so I'm going to get give the git repository and the curtain shows and I'm say it is taken from master so I will just do that that's it so we don't have to do anything else and this configure the configure in the pipeline okay now when I let us see if it is got pushed yeah push is successful now if I build this this should pull the pipeline the Jenkins file basically and it will do all the stages which we have defined here okay and let's check that okay if we notice here the first step is just checking out the codebase so just what is showing here it may open this in a new tab so that we can drag the status as well okay the code is getting checked out the code check out the successful let's go to the pipeline okay the pipeline shows that this code is checked out in 16 seconds the next stage is the compilation stage it is going on as well yeah compilation is also successful if you notice here yeah compilation is a crystal and it has moved to the testing phase so these are the stages which we if you notice here these are the names of the stages which we gave here right so the same stage names comes here so you can control the number of stages in the pipeline you can create a number of stages so you can automate the whole build and deployment process itself so based on the master or the develop deploy develop or the feature branch you can run specific tests so let's say you want or an integration test you can create an integration testing stage and then you can do that only for a specific branch or something or let's say you want to run a integration test with the database itself like like the production database all the UAT trip is all the David attack with it so you can also run that specifically for a specific branch using and you can control that using this gene cakes file and this uses groovy DSL so if you have a video with groovy syntax so you can write lots of code here you can write echo you can take all the groovy stuff inside this okay and there are lots of other plugins which you can use also if you notice bit maven is like pipeline maven plugin so that is I have used this meme but if you want to know what all that is and existing commands which we can use you can go to the plugin and chose of their eternity if you notice here the stage is completed so our build is completed our pipeline is completed if I trigger the build again it will show another line so it gets accumulated and you can see that if i refresh it so if you notice here it shows the next pipeline and it shows the different stages as well so this is easier for us to track the whole workflow and we will know where it is failed and you can test your code base case by face ok so that is the that is all about pipeline and that is how you configure piping so it is it is straightforward you just have to install the pipeline plugin along with that if you are using maven you can do to install maven integration pipeline plugin and if you want any other feature too we use you can use different plugins so in our case we are just going to you're just using the straightforward maven pipeline plugin and also the pipeline clicking ok so that is what we are using wave and crackle and breaking that is a very recent with maven and providing the major version if I you don't provide this maven will not be recognized when the build is run ok so this is how you create a pipeline using the Jenkins file that's it about this video so if you like my channel go ahead and like it if you want to see more videos go ahead and subscribe made again in the next video until then thank you you
Info
Channel: Tech Primers
Views: 420,174
Rating: undefined out of 5
Keywords: techprimers, tech primers, jenkins pipeline, how to create jenkins pipeline, jenkins continuous integration, continuous integration, jenkins pipeline example, jenkins pipeline tutorial, jenkins pipeline for beginners, ci jenkins, continuous integration jenkins, jenkins devops, jenkins pipeline workflow, jenkins pipeline plugin, jenkins build orchestration, jenkins build automation, jenkins pipeline automation, pipeline jenkins, pipeline as code, jenkins pipeline as a code
Id: s73nhwYBtzE
Channel Id: undefined
Length: 10min 10sec (610 seconds)
Published: Sat Jun 17 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.