Jenkins Beginner Tutorial 8 - Jenkins integration with GIT (SCM)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome to this session on Jenkins today we are going to see how we can integrate Jenkins with a source code management system and we will use git as an example for that so we will be creating a simple Java program and we'll run it through command line then we will create a Jenkins job and run the same Java program through the Jenkins job we will add our project to gate and then we will configure our Jenkins job so that it can trigger the execution on and commit to get so let us begin and let us see our step one will be create a Java program and I am using a Java program as an example to show you integration with git you can use your own project in whatever language it is so we we will create a simple Java program and you can create it in Eclipse or any editor I am directly using a text pad so if you are on Windows you can do it on a notepad or you can directly do on Eclipse so let us begin and let me just save this as a Java file first I will name it as hello and I will save it as a Java file so that you can see Java code here let me also increase the font okay so we'll create a class hello and we will create the main method and we will have our program written inside so let me just create a for loop so what I am doing is I am just creating a for loop for hydration 1 to 10 and inside the for loop I will just print something so let me just say system dot out dot println and let us just print hello world and give the i/o tration here so this is a simple java program that i have created which is printing hello world or 10 times ok so i I will just save it and I have saved it on desktop so or let us do one thing let me just create only you can see the file is saved here I will create a new folder by the name Java project 1 and I will move this file here ok so this file is here in this project now I have to run it through command line so I will go to my terminal and if you are on Windows you will go to your command prompt and rest of the things will be the same so I am going to terminal let me hide the sidebar so that you can see what is happening ok so what I have to do is I have to go to the location of this particular file so this file is located inside techstop and this folder so I will go here and now i will compile it so i will say Java C and the file name so I have compiled it and you can see hello dot class is created so that means the compilation is successful and to run it I will say Java and the name of the class without the extension and yes it is running so you can see it is printing hello world 10 times so in case you are you have created your project or program on Eclipse let us say I have this hello one dot Java on Eclipse in that case also you can run it through command line what we have to do is you have to go to the location or do the directory which is just above your package if you have created a custom package then you will go to a directory just above the package so in my case this is SRC so I hope you can see this I will go to this particular directory on my command line and it is here so I will go here and then I will do the same commands I will say Java C I will give the package name and the file name and then I will say Java and this time I will give the package name and file name without the extension dot Java and disk Genting hello world for me whatever was there in my program ok so there you can do it anyways so this was just an example to create a program ok so we have created our program now we can create a Jenkins job right so we will say create Jenkins job to run the program ok so for that let us start our Jenkins so first we have to go to the Jenkins directory so Jenkins is located in my case at desktop tools Jenkins and we will say Java - jar Jenkins dot war and it will start Jenkins on the default port 8080 but if I wanted to use some other port I will say - - HTTP port and I want to start it on let's say port nine one nine one so what it will do is it will start my Jenkins on port nine one nine one let us go to our browser and go to localhost 911 so this should get my Jenkins up and running in some time yes so it is getting ready so once the entire configurations are loaded we will have our Jenkins up and running and then we will create a simple job to execute this program it might take a couple of seconds sometimes yes it is fully up and running now so this should show my Jenkins window now okay so now I will go to a new item and I will create a program so I will say hello world freestyle project and I will say okay so it has created the job and now although we will use git but for now we just to test we will go to add build step and here if you are on Windows you will say execute windows batch command and if you are on Mac or Linux you will say execute shell so in my case I am going to select execute shell and here I will give the commands so the commands that I have to give is I have to go to my the location of my Java file first so this is the command to go to the location and then I will say Java C hello dot Java and then I will say Java hello so this should run my program let us test it I will apply and say and I will say built now let us look at the console output and yes it is it was able to run our program ok so we have successfully configured the job now we have to add our project to get so I will say add project to gate and github because you will create a repository on github so let us see what we do now so first let us go to the location of our folder here so this is the location of the folder that I want to add to get ok so you have to go inside the location and in your case it can be your project so if you are new to get and github I will recommend that you watch the session on git and github you can watch the big nurse session and you can watch how to install and get started if you are on Windows you can watch introduction and session 3 which is for Windows if you are on Mac you can watch session 1 introduction and session 2 which is fourth mech so this is very simple it will hardly take you five to 10 minutes to get started with git because I have already created separate sessions on get for this session I will just go with the command commands of grid directly so to initialize the repository I will say get in it and then I will say git status so it is showing me their two files which are not yet added so I will add with git add dot and now if I say get status yes these are added I have to commit it so I will say gift commit - M message added hello world program and yes and now I have committed but I have to push it to a remote repository so for that I have to go to my github account I'll go to github and see don't get intimidated with whatever I am doing now all this is explained in a very basic manner in the github tutorial so please watch them in case you are new to get and github let me just start a project here and let me give the name hello world and create the repository and now I will copy this location of the repository and I will say git remote add origin and the location of the repository and now I will say git push - u origin masters within the master branch all the projects should be pushed so it is done 100% if I go and refresh my depository on github I can see this has been committed and added to github okay now I have to configure my Jenkins job so step four will be the very first thing you will see is whether you have the Gator plug-in so you can go to Jenkins manage engines and here you have to go to your plugins manager you have to go to manage plugins and here you have to look for get plugin okay so this is the get plug-in now in my case it is already installed so I am finding it in the installed section in your case you will go to available and find get plug-in and install download and install it in case it is not already available once you have this available you will go to your project that we just created so this is the go to configure and here now we will you will have this get option ok you will only have this option once you have that plug-in available so I will click here and it is asking me the name of the repository the URL so this is the URL that we just created the repository okay so this URL I am giving here on my Jenkins job and now in the build triggers I will select pol SCM ok and here I have to give the cron expression that how often and and what intervals - you want this particular job to check the source code repository to check for the changes so or you can give any expression here based on your requirement of the project for now I am giving 5 stars which means it will check the repository every minute for any changes this is not recommended but just for demo purpose I am giving this so this job will check the git repository every minute and if there is any change it will trigger this job ok so I will say apply and save ok as of now you can see there is just one iteration and execution of this job which we have done manually the next item will happen whenever we are make any changes and push to our github so let us do some changes let me go to my or let me just create our new file here I will say touch in case you are on Windows you will say dir this symbol and whatever file you want to create ok it will it has created in back as well so I have created this file here you can also create by touch and the file name so if I want to create index dot HTML I will say this and it has created the file here ok so now I have made some changes if I do get stat it is showing me this is not added I will say get add and now if I do get status it is added I will do a git commit and give some message new files added and now I will say get to push - you origin/master and it should push the changes to get up and yes and now you can see this job it will it has started triggering the build it has started a job on itself and if you see the control output you can see this is started by an SCM change okay and everything is ok it has done our program and it has it is successful right so this is how you can create your project and add it to get and then create a Jenkins job to trigger whenever you make any changes in your project hope you like it thank you
Info
Channel: Automation Step by Step
Views: 310,757
Rating: undefined out of 5
Keywords: jenkins, jenkins and git, jenkins with git, jenkins scm, jenkins poll scm, jenkins integration with git, jenkins how to, jenkins basics, jenkins beginner, jenkins introduction, jenkins how to trigger, jenkins git plugin, jenkins beginner tutorial, learn jenkins, jenkins step by step, git and jenkins, git with jenkins, poll scm, jenkins how to integrate with git
Id: bGqS0f4Utn4
Channel Id: undefined
Length: 16min 4sec (964 seconds)
Published: Sat Oct 15 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.