We use Ubuntu system as a base for this tutorial.
Before we want to install Jenkins we need to install Java JDK.
Ubuntu is using Openjdk, to install it type the following to terminal:

$sudo apt-get install openjdk-7-jdk

Ubuntu installs the JDK (in my case)to the /usr/lib/jvm/java-7-openjdk-amd64/  folder. In additional, Ubuntu also puts the JDK bin folder in the system path, via symbolic link (/usr/bin/java).To verify that JDK is installed properly, type:

java –version

The output would be something like this:

java version "1.7.0_55"
OpenJDK Runtime Environment (IcedTea 2.4.7) (7u55-2.4.7-1ubuntu1)
OpenJDK 64-Bit Server VM (build 24.51-b03, mixed mode)

We need to configure JAVA_HOME. To configure JAVA_HOME do the following:
Check JAVA_HOME with the following command:

echo $JAVA_HOME

//show nothing if the JAVA_HOME is not set
Do the following steps to register the JAVA_HOME:
In terminal go to your user folder: /home/YourPersonalFolder
Type:

sudo gedit .bashrc

The .bachrc file will open in gedit
Add the following lines to the end of the file:

JAVA_HOME=/usr/lib/jvm/ java-7-openjdk-amd64
export JAVA_HOME
PATH=$PATH:$JAVA_HOME
export PATH

Restart the terminal and check that the JAVA_HOME is now configured properly:

echo $JAVA_HOME

The output should be like this:  /usr/lib/jvm/java-7-openjdk- amd64/

Now we are ready to install Jenkins.
Type the following lines to terminal to download and install Jenkins:

wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key
 | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > 
/etc/apt/sources.list.d/jenkins.list'
sudo apt-get update
sudo apt-get install jenkins

If you want to check and install updates for Jenkins, type the following to terminal:

sudo apt-get update
sudo apt-get install jenkins

The Jenkins is successfully installed and running. In the browser type: http://localhost:8080/
The Jenkins is in the 8080 port. Now we need to setup Jenkins.

First create user:
1.    Click to Manage Jenkins-> Configure Global Security and choose “enable security”.
2.    Select “Jenkins’s own user database” as the security realm
3.    Place a check mark next to “Allow users to sign up”
4.    Select “Matrix-based security” as the authorization
5.    Give anonymous user the read access
6.    In the text box below the table, type in your user name (you’d be creating this later) and click “add”
7.    Give yourself a full access by checking the entire row for your user name
8.    Scroll all the way to the bottom, click “save”

Jenkins.user.setup

At this point, you’ll be taken back to the top page, and Jenkins is successfully secured.
Restart Jenkins (http://localhost:8080/safeRestart)
Now you need to create a user account for yourself.
1.    Click “login” link at the top right portion of the page
2.    Choose “create an account”
3.    Use the user name you’ve used in the above step, and fill in the rest.
If everything worked out smoothly, you are now logged on as yourself with full permissions.
We will use Github repository for our project. Before we create our first job we need to setup GitHub.
In Jenkins:
1.    Click To Manage Jenkins  ->  Manage Plugins
2.    In Available tab type github to the search field
3.    Check GitHub Plugin and click to Install without restart
4.    In the setup page check “Restart Jenkins when installation is complete and no jobs are running”

Jenkins.intalling.plugin

After the install Jenkins will restart.
Optionally if the Git doesn’t want to work we can install it in terminal with the following command:

sudo apt-get install git-core

After it finishes downloading, you will have Git installed and ready to use. Also we can add the installed Git path to Jenkis in the following way:
In Jenkins open Manage Jenkins -> Configure System
In Git section type the git path to the „Path to Git executable” field.

Now we ready to create our first Job.

In the main page click to “New Item” from the menu. In the new page add a name to the Job and select “Build a free-style software project” and click OK. The Configuration page appears.
We can edit the configuration anytime from the left side menu -> Configure.

Important parameters:

GitHub project field – the URL to the github project. For example: https://github.com/YourName/tests/

Source Code Management section:
The Git repository is selected. There are two fields, Repository URL and Credentials.
To the Repository URL field we can write the URL, same as the repository URL just with “.git” in the end. (https://github.com/YourName/tests.git)
To the Credentials we need to add the Github Username/Password combination.

Build section:
We can use Execute shell build step type or Execute Windows batch command.
To the Command field we can write the actual command which Jenkins will execute.

Post-build Actions:
In this optional section we can handle the test outputs. For example if we use JUnit than we can select “Publish JUnit test result report” and add the report XML file path to it. After the test run the results will be available in Jenkins.

After we saved the configuration we can run the tests.
Click to “Build now” button and Jenkins will receive the files from GitHub and start the tests.

In the project page under the Workspace link we can view the files which Jenkis downloaded from GitHub.
In the Build History section we can see the process and the result. If the test is successful than the test marker will be blue, if some tests are successful but not all, than the marker will be yellow, if the test run was failed the marker will be red.
If we click to the uppermost link in Build History we can see the results page with the latest results. In this page we can view also the console output.

Posted By István Lackó

Leave a Reply




XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>