Hi everyone and welcome back to the “Get started with Jenkins” series.
In this video I’m going to show you how to get your source code from a git repository
into Jenkins. This is obviously very crucial as you want
to perform tests on your code and ultimately deploy it!
So what’s next for this video? Well first of all I’m going to install git
onto my Jenkins server. Than I’m going to install the git plugin for Jenkins, I’m
going to create a new job and configure the git integration and than we’re going to
test if everything works correctly.
So let’s begin!
So the first thing that we have to do is: we have to install Git onto our Jenkins server.
Here I've opened up an SSH connection to my Jenkins server. The only thing that I need
to do to install git is simply run "sudo apt-get install git". This will take care of the installation
of git.
So now that git is installed, we can install the git plugin for Jenkins. This plugin basically
teaches Jenkins how it can communicate with the git program. So I'm going to open up my
browser and I'm going to go to my Jenkins installation (which is on my local network).
And I'm going to click on "Manage Jenkins". Now in this page we're going to go for "Manage
plugins" to add the new plugin. And then I'm going to open the tab "Available". In here
I get a list of all the available plugins for Jenkins. There is also a filter option
here, so in the filter option I'm going to type "Git plugin". In the search results here,
the last one is "Git plugin" and it says "This plugin allows the use of git as a source control
management". Okay, so that's what we want! I'm going to click on this and click "Download
now and install after restart". After this it's required to restart Jenkins so I'm going
to tick this box here and wait until Jenkins is restarted.
So after the restart of Jenkins I went back to the homepage. Now it's time to create our
very first job. So I'm going to click on "Create new jobs" and I'm going to give my job a name,
I'm going to call it "my-first-jenkins-job". I'm going to create a freestyle project so
that we have full control over it. In the next screen we can instruct Jenkins on what
it should do when we trigger a build. Now what we want to do is we want to tell Jenkins
that if a build is started, you should download the source code of our project. So to do that,
you have to go down to the "Source Code Management" section and click on git.
And here we can tell Jenkins on where our git repository and I'm going to give it the
URL of one of my public repositories on GitHub. This is jsTixClock, it's a Tix clock written
in Javascript, it's really cool! You should check it out.
Now if this repository was private, I could instruct Jenkins to use some credentials to
authenticate with this repository. But since this repository is public, that's not needed.
In the next section I can tell Jenkins which branch it should build. Now I'm going to leave
this to default because all my code is in the master branch. Pretty much the rest of
the setting for git I'm going to leave to default as well and I'm just going to hit
the save button. So now that that is done, we can manually trigger a build. In the left
column you can click on "Build now" to actually start the build.
And now Jenkins will run through all its tasks, but since we only added the git task it will
just download our source code and do further nothing. So naturally the build finished really
quickly. So if I go here on the first build I can see everything went well. I can go to
"Console output" to see some more details and here I can see that it's actually cloning
the remote git repository and that it has finished with a success.
So that’s it for this video. We manually started a build in Jenkins. Want to learn
more about Jenkins? In the next video I’ll show you how to integrate
Jenkins with BitBucket so that you don’t have to manually start the build after a commit.
Thank you very much for watching this video. If you like my videos, make sure to subscribe
to my channel or follow me on Twitter.