Jenkinsfile Beginner Tutorial 2 | How to get Jenkinsfile from Git SCM

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in the last session we have seen how we can  create a jenkins pipeline using a jenkins   file within a jenkins job now let us see  how we can get this jenkins file from git   or any source code management system  and then use it in our jenkins job   so here let's get started with step  number one you can create a new job or use existing job and it should be of type  pipeline and we have already created a job of type   pipeline in the earlier session so i'm going to  use that job this is pipeline one that we created   and here if i go to configure you can see  we have already run some of the pipelines   and if i go to configuration page of this  job and go to pipeline you can see this is   what we used here we have two options we have  pipeline script and pipeline script from scm   in the early session we used this and we added  this jenkins file here now i'm going to create   a git repository so i will say create a repository  on github and you can use bitbucket or any other   cloud repository or a git repository for this  i will go to google and search for github   and go to github.com and you can create a free  account here and do a sign up in my case i will   do a sign in i already have an account i  will add my user and password and sign in   and i'm going to create a new repository here you  can go from here and say new repository or just go   from here and click on new and here i have to give  a repository name i will say jenkins pipeline demo   and you can give some description which is  optional and you can make it public or private   i will keep it public so i do not have  to add credentials although i will   show you how to add credentials in your  jenkins and i will say create repository   so this is my git repository on github  now the next step is step number 3 will be   add jenkins file in the repository now inside your  git repository you can create a file and commit it   on your repository now you can do it from your  local system and then commit it here just in case   you want you can watch my git and github tutorials  but for now i am going to keep it very simple   i will go and click here so here it is create a  new file and even if you do not get this option   from here i will show you later as of now  i am going to click on create a new file   and here i will give the file name now i am saying  jenkins file although you can name it anything we   will anyways have to provide the location on our  junkies job so i will say jenkins file or you can   say abc123 whatever you want and here in this  file i want to add the script of my stages as   we do in the jenkins file as we have done in our  earlier session so this is the declarative script   the groovy script that we add in our jenkins file  and i'm just going to add it here and now i will   commit this file now just in case you want to  add any other file you can go from here and   create a new file and add it now as of now i have  added this file so from my jenkins in my gen keys   job i will now say pipeline script from scm and  the scm i am going to use is git and this comes   if you have the git plugin added in your jenkins  just in case you do not see this option you can go   to manage jenkins manage plugin and add the git  plugin now i have to give the repository url so   this is my url i will click here i can copy the  url from this address bar or i can also copy it   from here both will work i will add the url here  and now if this is a private repository i will   need to add the credentials otherwise i can leave  it just in case you have to add you can go here   click on jenkins and give your github username in  this case i will i'm using github so i will say   my github username my github password if you  want to give any id that is fine otherwise   it will auto generate and i will say my github  credentials here and say add and now here i can   just add these credentials and then i have to  select the branch so if i see on my repository   the branch that i have is called main i'm just  going to change from master to main here and now   here i have to give the script path now in my  case i am calling it as jenkins file so if this   is fine i can keep it as it is otherwise if you  have any other name you can give the name here   also if you have your file in some folder then you  can give the folder name first for example you can   first say whatever your folder name is and then  forward slash whatever your file name is so you   can do that just in case you have any issues  you can always click on these question marks   which will give you the description how you have  to give this field so you this will help you now   this is done i will say step number four is add  repo and jenkins file location on the in the job   under pipeline section or i should say even before  this step number four should be under jenkins   job pipeline section select so we have  to select here pipeline script from scm this is the definition and now i should  save and run so i'm going to apply   and save and i will say build now and let us  see we have already done three builds of this   pipeline and you can see the fourth build is here  and everything is fine and you can see all this is   now coming from our repository the jenkins file is  coming from the repository and now it is running   i can go and check the details in the console  output and you can see this is coming from our   repository which is here github jenkins pipeline  demo and it is first cloning the repository   and you can also see the location where this  repository is cloned if i go to this location   i will see my jenkins file from the repository so  if i just go to my folder and go to this location   you will see this jenkins file has come here  and then it is running all the stages that we   had on our jenkins file and if i go back to  the project and i will say build now again   and you will see the next build of this  pipeline and everything is running fine   so this is how you can get a  jenkins file from get scm and then   run the jenkins pipeline i hope this was  useful for you thank you for watching
Info
Channel: Automation Step by Step
Views: 14,051
Rating: undefined out of 5
Keywords: how to use jenkinsfile, how to create jenkinsfile, how to clone git re, how to get jenkinsfile from git repository, how to get jenkinsfile from jenkins, what is jenkinsfile, how to script in jenkinsfile, jenkins file for, jenkinsfile for pipeline
Id: 8IWH1cYVZt4
Channel Id: undefined
Length: 7min 27sec (447 seconds)
Published: Sun Jan 17 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.