Setting up Jenkins with GitHub
|This document is part of a series of documents covering Continuous Integration setup for a UI5 application.|
In a typical software development model, there are multiples programmers contributing to the same codebase. This causes many bugs in the codebase, which significantly slows down development.
Continuous Integration is a practice that involves developers checking-in their code several times a day to a central code repository. Each time code is checked in, automated builds and tests run. Since this happens several times a day, problems are detected early and they are resolved before development continues further. This practice requires: a Continuous Integration server which runs the automated builds and tests; a version control system that tracks changes in the codebase.
In this setup, we will use:
- Jenkins: an open-source continuous integration server.
- Git: a Version Control System
- GitHub: to host the code repository online, so that multiple developers can access it over the internet. GitHub is a web-based Git repository hosting service that can be used free of cost.
Figure 1: Continuous Integration setup with Jenkins
In this article, we shall cover the section shown in orange. This focuses on the steps required to enable Jenkins to communicate with GitHub.
There are several ways of connecting Jenkins to a remote repository on GitHub (SSH, HTTPS, Subversion). In this tutorial, we use SSH authentication, as this eliminates the need to enter your username and password every time you run a Git command. Also, this eliminates the need for a local issuer certificate (SSL) on Jenkins.
- GitHub (github.wdf.sap.corp) account is set up with a repository.
- Git for Windows is set up on your computer, using SSH for authentication. (A tutorial on this is available here.)
- Jenkins is installed on your computer [with Git plugin installed].
2. Configuring Jenkins for Git
Open your Jenkins Dashboard.
Go to: Manage Jenkins > Configure System
Under ‘Git’, add a new Git installation with the ‘Path to Git executable’ set to: C:\Program Files\Git\cmd\git.exe
NOTE: It is necessary to use this particular git.exe file. There will be multiple git.exe files in other folders. However, pointing Jenkins to any other git.exe file will give you a humongous stack trace of an exception beginning with: ssh executable not found.
3. Running Jenkins as a service of your user account
Open Task Manager > Services > Open Services
Select ‘Jenkins’ from the list > Right-click > Properties
Go to the “Logon” tab
Select ‘This account’, and enter your local account name and password (including domain details, if required).
Restart Jenkins to allow the changes to take effect.
4. Setting up Credentials in Jenkins
Open the Jenkins dashboard.
Go to: Credentials > Global credentials > Add Credentials
The ‘Kind’ and ‘Scope’ will be as shown above.
For the Username, enter your GitHub username.
Select ‘From the Jenkins master ~/.ssh’ for the Private Key.
Enter the passphrase that you used while setting up SSH. Leave it blank if you didn’t use any passphrase.
5. Setting up a project in Jenkins
New Item > Free Style project
For ‘GitHub project’, enter the URL of the repository on GitHub.
Under ‘Source Code Management’, select ‘Git’.
Enter the URL of the repository in SSH format.
Select credentials that you set up in step 4.
TABLE OF POSSIBLE ERRORS
javax.servlet.ServletException: java.lang.RuntimeException: ssh executable not found. The git plugin only supports official git client http://git-scm.com/download/win
|In your Jenkins global configuration, the Path to Git Executable is not pointing to the git.exe provided by the official Git for Windows client.||In your Jenkins server, go to Manage Jenkins > Configure System and set ‘Path to Git Executable’ to C:\Program Files\Git\cmd\git.exe|
|Failed to connect to repository : Command “C:\Program Files\Git\cmd\git.exe -c core.askpass=true ls-remote -h email@example.com:I322118/FBA_StandardTiles.git HEAD” returned status code 128:
stderr: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
|Jenkins is running as a service on the local user account instead of your account.||Follow Step 3 to run Jenkins as a service on your user account.|
Failed to connect to repository : Command “C:\Program Files\Git\cmd\git.exe -c core.askpass=true ls-remote -h https://github.wdf.sap.corp/I322118/FBA_StandardTiles.git HEAD” returned status code 128:
|You are using an HTTPS URL to your GitHub repo instead of an SSH URL.||
Go to your GitHub repo, and click on ‘SSH’ and copy that URL. It should be in the following format:
You should now be able to execute a build and see it pass, if Jenkins successfully fetches your code from GitHub. The next step is to set up builds and tests that run on the code that you push to GitHub.
In the next article, we will talk about Test-Driven Development in UI5 applications, and the various tools available to this end. This will help us set up ‘Unit tests’ shown in the ‘NodeJS Plugin’ section in Figure 1.
This article was written with the contribution of : MOUNIKA GANTA