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.
- First, we need to create a New Project in Jenkins. Open Jenkins (http://localhost:8080/).
- Click on ‘New Item‘ link.
- Enter the Project Name. For me, it’s ‘SeleniumBix’.
- Chose the option ‘Freestyle project‘ and click on ‘OK’ button.
- In project configuration on Jenkins. Scroll down the page up to section ‘Source Code Management‘.
- Here, Select the radio button for ‘Git’.
- 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
- 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)
- Open your browser and open Jenkins.
- Go to ‘Manage Jenkins’ by click on ‘Manage Jenkins’ link.
- Inside Manage Jenkins, find and click the option ‘Manage plugins‘.
- Here click on ‘Available’ tab and find the all available plugins.
- Now search for the ‘GitHub plugin‘. Find it click on the checkbox present for this plugin.
- Now click on the button ‘Download and Install after restart’.
- 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.
- Open the Jenkins and click on the target ‘Project’.
- Click on the ‘Configure‘ link present in the top – left menu.
- Scroll down to ‘Build Triggers‘ section.
- 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.
- Go to Project Directory.
- Open Git Bash using right click.
- Perform git add .
- Perform git status
- Perform git pull
- Perform git commit -m “Check-in Signature”
- 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.
Products from Amazon.in
Price: Check on Amazon
Price: INR 29,950.00
Price: INR 17,999.00
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)