Jenkinsfile Beginner Tutorial 1 | What is Jenkinsfile | How to create jenkinsfile | Step by Step

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this session we are going to learn what is  jenkins pipeline and how do we start a jenkins   pipeline and how do we create a jenkins file this  is going to be a very basic beginner session so   do not worry if you have never understood what is  jenkins pipeline or what is a jenkins file i will   go very basic step by step and before i write  down the steps and show you the demo let us see   what is pipeline and what is jenkins pipeline so  i will just go and here you can see until now on   our jenkins we have been creating jobs on the gui  and we create a job from here and then add all our   details of the job in the job configuration and  then we run from here now if i go and search for   continuous integration and delivery on google  and if i go to images and here uh let us see this   image here so if you see here here we have kind  of a pipeline and in a pipeline we have multiple   jobs or processes linked together that is one  runs after the other and they are all executed   with an automatic trigger so for example here is  a dev job or a dev process if this is successful   it will then trigger the test process and if this  is successful it will then do the integration part   and therefore you can see whether we are doing  continuous integration or delivery or deployment   all these phases all these jobs are linked  with each other they are sequenced and   linked in the chain and they have automatic  trigger now when i talk about jenkins pipeline   jenkins pipeline is a process or a way to  implement this cicd process and if you see   any of these images you can see here so let  us say we have these jobs we have a built job   here or a build stage we have a integration  testing other testing and then approval and   deploy and this is a pipeline so all these  jobs are linked with each other and this is   exactly what we are going to create  using a jenkins file in this session   so jenkins pipeline is a way of jenkins to  implement ci cd that is continuous integration   delivery and deployment and that basically means  all these jobs that you have in your project   all the stages of your project starting  from build so starting from the dev build to   deploy to test and release all these stages  or all these jobs can be integrated or chained   with each other using jenkins pipeline and to  implement jenkins pipeline we use a file called   as jenkins file so jenkins file is basically  pipeline as a code we call jenkins file as   pipeline as a code because in this jenkins file we  will write a code or we will write a script now do   not worry it is going to be very easy don't think  that you do not have any programming or coding   experience i will show you very basic step by  step how to do this so basically we write a script   or we add the instructions in the jenkins file  to implement the pipeline or to run all these   stages that is build deploy test and release and  this is this can be anything for example you have   your project where you have some different stages  you can do that in a jenkins file so that is a   jenkins file and now i will show you how to create  jenkins file and how to implement jenkins pipeline   or pipeline in jenkins so step number one is  start your jenkins and i believe you have already   started your jenkins and i am here on my zen case  it is already started and i have some jobs here   now what i am going to do is install pipeline  plugin so this is the second step that we need   to install the pipeline plugin and let me very  quickly show you if you go to manage jenkins   and go to manage plugins first thing you can do is  go to the installed section and check for pipeline   so most of the cases if you have added all the  suggested plugins while installing or starting   jenkins for the first time you may already have  a pipeline plugin installed so if i search here   you can see here it is so this is the pipeline  plugin that we need so this is what we need just   in case you do not find it here you can always go  to the available section find this plugin and then   you can say install without restart and install  the plugin and once you have the plugin installed   go to step number three that is create a new job  i will go on my dashboard and now i will create   a new job sorry i will have to go back and i  will just have to click on this new item here   and i can name it anything pipeline one or you can  give any name here now the type should be pipeline   here until now we have been selecting freestyle  project but now it should be pipeline and this   option will come only after you have added the  plugin so click on this pipeline and say ok   now here you will see general section like in  earlier projects and then you will see build   triggers here we have all these options then you  will see advanced project options and if you click   on advanced here you can just add the name of  the project here and then we have a section   for pipeline and this is where we can create a  jenkins file or we can get a jenkins file from our   cloud repository or source code management tool  or depository now here i will say step number   four create or get jenkins file in pipeline  section so here if you see we have option   here we have pipeline script and here we have  two options either i can create a pipeline script   within this job that is here or i can also  get it from a source code management tool like   git or github or any cloud git repository or any  source code management system for now i will say   python script and in the next session i will  show you how you can get it from a source code   management system so i will select pipeline script  here and now here is where you can write your   code or script and if you go to this  drop down here you can see we have   some sample scripts like hello world get a plus  maven and scripted pipeline a jenkins file can   be written in two ways a declarative format or a  scripted format the scripted way or the scripted   structure is the older way and the declarative way  is the more recent ways of writing a jenkins file   both of these uses groovy there is a difference  in the structure and format and in the drop down   you can see all these options are for declarative  but you can also select scripted pipeline here you   will see a sample here this is how we create a  scripted pipeline we give a node here and then   define our stages and give all our steps here  so there's a build stage and here you can see   all the steps what should be done in the build  stage then all this is here this is the earlier   scripted pipeline way but this time i'm going to  use the declarative format and here i will select   the hello world pipeline here now if you see here  it starts with pipeline we say pipeline and the   curly bracket start and the curly brackets stop  inside this we give the agent if we have to run   this on a particular agent we can give the name  here or if it can be run on any agent i can say   any then i say stages and under this i will give  the stage name so this is hello and then i can   give the steps of this stage here i'm just saying  echo hello world so this is a very very simple   jenkins file where we are having a single  stage called hello and inside the stage   we are printing hello world on the console in real  world the stage name can be something like build   deploy test etc and in the steps you will have all  the steps that you will be needing to do in that   particular stage but for now let me keep it very  simple as it is i have got this jenkins file and   here is what i have written now if you want you  can also click on this pipeline syntax and this   will take you to the page where you can actually  create steps for example i want to create a build   step that is build a job in the pipeline i will  select the job let us say i say deaf job this is   one of the jobs on my jenkins and then i can give  some quiet period like five seconds or something   you can always click on these question marks  to see what exactly this field means and then   i will say generate pipeline script and  you can see this is what i can use in my   jenkins file so just in case you have to need you  need any help you can always come here and then   select what you exactly want to do and generate  the script for that for now i will say apply   and save and now the job is saved and now i will  click on build now and let us see what happens so   you can see this is running here and once this is  executed you will see we have got this stage view   here so we had a stage the stage name is hello and  you can see the name here and then you can see the   time taken by this particular stage and this is  the first pipeline you can see number one here   and then the date and there are no  changes from the source code management   and then this is the time taken and this is  the average time taken now if i run it again   you will see now this is the second pipeline  or the second run of the pipeline and this is   a time taken and this is the average time of this  particular stage and if i go to any of the runs   and go to console output you can see  this is how the stage or the output   looks like so in this particular stage  we are just printing this on the console   now let me go back to the project and i will go to  configure again and i will go to pipeline now here   i want to add some more stages so i am just  going to copy this and hit enter and paste it   and paste it again so let us say this is my hello  stage which is where i'm just printing hello world   let us say this is my build stage and here  i'm saying building now as i have said in   real world you will have your actual steps to  build some project here then i will say deploy and i will say here deploying and let us say  i will have one more stage here called test and i will say testing here and then i will have a  stage called release and i will say releasing here   and i will again apply and save and now  i will build again and now you can see   and here you can see all these stages have come  so this is the build stage deploy stage test   stage and release and i can go and check the  lock for any of the stages this is as of now   i'm only printing building here similarly  if i check the logs it is printing testing   but otherwise you will have your actual build  steps here and this is exactly how this looks like   as we have seen earlier so here i will say run and  check the output so this is in very very simple   words in very very simple way how you can start  with jenkins pipeline and jenkins file in the   next session i will show you how you can create  this jenkins files in your source code management   system and then get it on jenkins and run from  jenkins i hope this was useful thank you for watching
Info
Channel: Automation Step by Step
Views: 27,673
Rating: undefined out of 5
Keywords: What is pipeline, What is jenkins pipeline, What is jenkinsfile, How to create jenkinsfile, jenkins declarative pipeline tutorial, jenkins scripted pipeline tutorial, jenkins scripted pipeline vs declarative, jenkins beginner tutorial, jenkins raghav pal, jenkins interview questions, jenkins interview questions for devops experienced, jenkins interview questions for automation testers
Id: RsD2nzPY0is
Channel Id: undefined
Length: 12min 22sec (742 seconds)
Published: Thu Jan 14 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.