SetUp Jenkins with GIT

Price: INR 1,299.00
Was: INR 1,799.00

In this tutorial, you will see, How can you Setup Jenkins with GIT or  How can you connect the Jenkins Repository with Git.

In the previous tutorial we have seen, How can we upload the repository on Server

 

In this tutorial we will see, How can we connect the Jenkins repository with our local Git and configure the project in this way that Jenkins execute the project build on every check-in and verify the Project source code.

 

Create FreeStyle Project in Jenkins

Let’s see how can we do this.

  1. First, we need to create a New Project in Jenkins. Open Jenkins (http://localhost:8080/).
  2. Click on ‘New Item‘ link.
  3. Enter the Project Name. For me, it’s ‘SeleniumBix’.
  4. Chose the option ‘Freestyle project‘ and click on ‘OK’ button.
  5. In project configuration on Jenkins. Scroll down the page up to section ‘Source Code Management‘.
  6. Here, Select the radio button for ‘Git’.
  7. As you click Jenkins will ask for the Repository URLs. Here, In ‘Repository URL’ enter the URL of your GitHub Repository for me it’s — https://github.com/anshulc55/SeleniumBix
  8. Now, click on the save button.

 

Now we have configured the Jenkins project with our GitHub Repository. Now we want Jenkins will auto execute or make the build as we make some change in GitHub Repository. For this, we need to install the ‘GitHub plugin’ inside the Jenkins. (You remember we also have installed Git plugin in Jenkins in last tutorials)

  1. Open your browser and open Jenkins.
  2. Go to ‘Manage Jenkins’ by click on ‘Manage Jenkins’ link.
  3. Inside Manage Jenkins, find and click the option ‘Manage plugins‘.
  4. Here click on ‘Available’ tab and find the all available plugins.
  5. Now search for the ‘GitHub plugin‘. Find it click on the checkbox present for this plugin.
  6. Now click on the button ‘Download and Install after restart’.
  7. After complete, the downloading plugins check the checkbox ‘Restart Jenkins’.

Well, we have installed the plug-in now. After this again we need to perform some changes in Project Configuration.

  1. Open the Jenkins and click on the target ‘Project’.
  2. Click on the ‘Configure‘ link present in the top – left menu.
  3. Scroll down to ‘Build Triggers‘ section.
  4. Here you will find the new option ‘Build when a change is pushed to GitHub‘. Check this checkbox and click on save button.

 

We have done the all required changes. Now, whenever you perform some changes in your local code and check-in your code to the server machine. Jenkins will automatically run and verify the source code for any error.

 

So this is all, How Jenkins execute the build for each and every check-in. We have seen in the last tutorial, How can we perform the code check-in to our server repository in the last tutorial.

 

For example, you can add the new class to your project and check-in the code using Git Bash.

  1. Go to Project Directory.
  2. Open Git Bash using right click.
  3. Perform git add .
  4. Perform git status
  5. Perform  git pull
  6. Perform git commit -m “Check-in Signature”
  7. Perform git push -u origin master

 

You have successfully check-in your changes on the server. Jenkins will detect that there are some changes in GitHub linked repository so it will automatically execute the Build and verify the error.

 

If you want to execute some test cases after each check-in then you can create the ANT file for these and include ANT action in Build after build creation configuration. (We will learn about in details in ANT Tutorials)

 

0 Comment

Leave a Reply