Copyright © 2012, 2013 Lars Vogel
|Revision 0.1 - 1.2||27.07.2012 - 01.05.2013||Lars
|bug fixes and enhancements|
Table of Contents
Continuous integration is a process in which all development work is integrated at a predefined time or event and the resulting work is automatically tested and built. The idea is that development errors are identified very early in the process.
Jenkins is one open source tool to perform continuous integration. The basic functionality of Jenkins is to monitor a version control system and to start and monitor a build system (for example, Apache Ant or Maven) if changes occur. Jenkins monitors the whole build process and provides reports and notifications to alert maintainers on success or errors.
Jenkins can be extended by additional plug-ins, e.g., for building and testing Android applications.
To use Jenkins you need:
An accessible source code repository, e.g., a Git repository, with your code checked in.
A working build script, e.g., a Maven script, checked into the repository
Jenkins can be started via the command line or can run in a web application server. Under Linux you can also install Jenkins as system service.
Jenkins provides Debian/Ubuntu packages which install Jenkins and register Jenkins as start service. See the following URL for details.
This installs a
start script which starts Jenkins automatically at boot time.
If you start it locally, you find it running under the following URL: http://localhost:8080/
For most platforms you have native packages, see the Jenkins Homepage.
You can also start Jenkins directly via the command line with
java -jar jenkins*.war.
If you start it locally, you find it running
under the following URL:
To run it in your Tomcat server, put the .WAR file
directory. If you start
Tomcat, your Jenkins installation will be
If you want to install Jenkins in a web container, you can use, for example, Tomcat or Jetty. See the Apache Tomcat Tutorial.
In this example we use Apache Ant to build a simple Java project. Please see the Apache Ant tutorial for details.
We use Git in this example. Please see the Git tutorial for details.
Before using Jenkins you need to tell it where your JDK and ant installation is. Open Jenkins in your browser and click Manage Jenkins and then Configure System.
Enter the correct path to your JDK, Apache Ant and Maven and press thebutton below. Jenkins can also install these for your automatically.
It is recommended to secure Jenkins. Manage Jenkins and then Configure Global Security. Select the Enable security flag. The easiest way is to use Jenkins own user database. Create at least the user "Anonymous" with read access. Also create entries for the users you want to add in the next step.
On the login page, select Create an account to create the users you just gave access.
Go to Manage Jenkins, Manage and Assign Roles and then Assign Roles to grant the newly created user additional access rights.
to define access restrictions in detail.
Pattern is a regex value of the job name.
The following grants unregistered users
read-only access to your build jobs that
start with the
M-MASTER prefix and only those.
Jenkins supports the Git version control system via a plugin. Select the Git Plugin.→ link. Here you have to install the
To clone a Git repostory via Jenkins you need to enter the email
user name for your Jenkins system. For this switch into your job
directory and run the
# Need to configure the Git email and user for the Jenkins job # switch to the job directory cd /var/lib/jenkins/jobs/Android/workspace # setup name and email sudo git config user.name "jenkins" sudo git config user.email "email@example.com"
The build of a project is handled via jobs in Jenkins. Select New Job " and select Freestyle Job to create a new Job in Jenkins.
To create a build job on Jenkins you need to have a working build setup. See Android build tutorial.
Jenkins supports the automatic building and testing of Android applications. To start your tests on an emulator you can use the Android Emulator Plugin. The Android Emulator Plugin supporting starting and unlocking and blocks the build until the emulator has started.
A detailed description of this plugin can be found under the following URL: Android Emulator Plugin Jenkins page.
To install this plug-in use the→ link and search for "Android". Select it from the list and select to install it and restart Jenkins.
For automated tests it is good practice to have another job which executes the tests. This job can be connected to the build job of the application so that it runs automatically after this compile step.
To create an Android build job on Jenkins, select New Job, enter a job name and select the Build a free-style software project option.
You configure from where the source should be cloned.
You configure the emulator which should be started. Ensure that you do not select the Show emulator window option, as your build server should not depend on the availability of a display server.
You may see the following error message: "Error: Invalid --abi ... for the selected target" in the log of your job. In this case you have to install the desired Andoid images manually with the following command.
// run this as Jenkins user /var/lib/jenkins/tools/android-sdk/tools/android update sdk --no-ui
Use /var/lib/jenkins/tools/android-sdk/tools/android list targets to see what ABIs are installed. If no are listed manual install one.
Configure the Apache Ant build file, use the Advanced option to specify the location of the build file.
The Android Emulator Plugin supports a new job with the Build multi-configuration project option. This option allows you to test multiple emulator configurations at the same time. You can, for example, test different languages, densities, screen resolutions, etc.
Typically you have two Jobs, one for a simple build and test run and a multi-configuration project to test the build on different device configurations.
You can combine Android Emulator Plugin with the Amazon-EC2-Plug-in to run the build and the tests on several machines simultaneously.
Jenkins stores all the settings, logs and build artifacts in its home
directory, for example, in
under the default install location of Ubuntu.
To create a backup of your Jenkins setup, just copy this directory.
directory contains the individual jobs configured in the Jenkins
install. You can move a job from one Jenkins installation to another
by copying the corresponding job directory. You can also copy a job
directory to clone a job or rename the directory.
Clickbutton in the Jenkins web user interface to force Jenkins to reload configuration from the disk.
See Adminstration of Jenkins for details.
This tutorial is Open Content under the CC BY-NC-SA 3.0 DE license. Source code in this tutorial is distributed under the Eclipse Public License. See the vogella License page for details on the terms of reuse.
Writing and updating these tutorials is a lot of work. If this free community service was helpful, you can support the cause by giving a tip as well as reporting typos and factual errors.
Please consider a contribution if this article helped you. It will help to maintain our content and our Open Source activities.
If you find errors in this tutorial, please notify me (see the top of the page). Please note that due to the high volume of feedback I receive, I cannot answer questions to your implementation. Ensure you have read the vogella FAQ as I don't respond to questions already answered there.