|This document is part of a series of documents covering Continuous Integration setup for a UI5 application.|
In the last article we configured a build on Jenkins to run unit tests and lint checks. We now focus on triggering a build in Jenkins when you push code to a GitHub repository.
Figure 1: Continuous Integration setup with Jenkins
Running builds as soon as code is pushed to the central repository is important, as it enables you to detect problems quickly and locate them more easily.
To know how to configure a Jenkins build for a UI5 project, please refer to Setting Up Jenkins with GitHub.
Before you can start with the process given below, you will need to install the GitHub plugin on your Jenkins server.
N.B.: At the end of this document is a video in which all the required steps are carried out. You could watch the video for a quick setup.
1. Configuring Jenkins
Although we have configured Jenkins to communicate with our repository on GitHub, we still have to manually start the build from Jenkins. To automatically run builds, Jenkins listens for POST requests at a Hook URL. We need to give this URL to the repository on GitHub. Then, whenever code is pushed to that repository, GitHub will send a POST request to the Hook URL and Jenkins will run the build.
To get the Hook URL of Jenkins, Open the Jenkins Dashboard.
Go to: Manage Jenkins > Configure System
Under GitHub Plugin Configuration, Click on ‘Advanced…’
Check ‘Specify another hook url for GitHub configuration’
A textbox will appear with a hook URL. This is the Hook URL at which Jenkins will listen for POST requests. Copy this URL and go to the next step.
2. Configuring GitHub Repository
We now have to provide the Hook URL we got from Jenkins in the previous step.
Open your repository on GitHub.
Click ‘Settings’ on the navigation bar on the right-hand side of the screen.
Click ‘Webhooks & services’ on the navigation bar on the left-hand side of the screen.
Paste the URL you copied in the previous step as the ‘Payload URL’.
You can select the events for which you want the Jenkins build to be triggered. We will select ‘Just the push event’ because we want to run the build when we push our code to the repository.
Alternatively, you can click on ‘Let me select individual events’ to get a list of all the events that you can select to trigger your Jenkins build.
Click ‘Add webhook’ to add the webhook.
You should now see the webhook you just added in the list of Webhooks for that repository like this.
3. Configuring Jenkins Project
We now have Jenkins configured to run builds automatically when code is pushed to central repositories. However, Jenkins doesn’t run all builds for all projects. To specify which project builds need to run, we have to modify the project configuration.
In Jenkins, go to the project configuration of the project for which you want to run an automated build.
In the ‘Build Triggers’ section, select ‘Build when a change is pushed to GitHub’.
Save your project.
Jenkins will now run the build when you push your code to the GitHub repository.
Here’s a video with all the above steps being done:
With this article, we come to the conclusion of the three part series where we configured a Continuous Integration server running Jenkins for a SAPUI5 project. If you have read all the articles, you will now be able to:
- Configure a continuous integration server (running Jenkins) to communicate with a repository on GitHub (Setting Up Jenkins with GitHub).
- Configure the continuous integration server to run unit tests and lint checks as a part of the build (Configuring Jenkins for Unit tests and Lint checks).
- Configure the continuous integration server to automatically run your build when code is pushed to your repository on GitHub (this document).
Continuous Integration is a practice that helps detect errors quickly and locate them easily. Once a culture of continuous integration has been set up, the next step is Continuous Delivery. Continuous Delivery is a set of practices that ensures that all the code that is produced is ready for deployment. In the next series, we will look at how we can implement continuous delivery for a SAPUI5 project.
This document was written with the contribution of: MOUNIKA GANTA