Preparing the Jenkins environment

In this section, we will take you through the steps to install Jenkins, the GitHub plugin for Jenkins and git, and the revision control tool. The steps are as follows:

  1. We begin with adding the Jenkins' trusted PGP public key:
      $ wget -q -O - 
https://jenkins-ci.org/debian/jenkins-ci.org.key |
sudo apt-key add -

Here, we are using wget to download the PGP public key, and then we add it to the list of trusted keys using the apt-key tool. Since Ubuntu and Debian share the same software packaging, Jenkins provides a single common package for both Ubuntu and Debian.

  1. Add the Debian package location to the apt package source list, as follows:
      $ sudo sh -c 
'echo deb http://pkg.jenkins-ci.org/debian binary/ >
/etc/apt/sources.list.d/jenkins.list'
  1. After adding the package source, continue to run the apt-get command update option to resynchronize the package index from the sources:
      $ sudo apt-get update
  1. Now, install Jenkins using the apt-get command install option, as demonstrated here:
      $ sudo apt-get install jenkins
  1. Finally, activate the Jenkins service using the service command:
      $ sudo service jenkins start

The Jenkins service can be accessed through any web browser by specifying the IP address (54.86.87.243) of the system in which Jenkins is installed. The default port number for Jenkins is 8080. The latest Jenkins 2.62 is already installed. The following screenshot is the entry page or dashboard of Jenkins:

  1. Provide the password from the file and login. This user is the admin:
      $ sudo cat 
/var/lib/jenkins/secrets/initialAdminPassword
b7ed7cfbde1443819455ab1502a19de2
  1. This will take you to the Customize Jenkins page, as shown in the following screenshot:
  1. Select Install suggested plugins on the left-hand side of the screen, which will take us to the installation page.
  1. On the Create First Admin User page, select Continue as admin:

This will take us to the Jenkins is ready! page, as shown in the following screenshot:

  1. Now, clicking on the Start using Jenkins button will take you to the Welcome to Jenkins! page:
  1. Ensure that the git package is installed, otherwise install the git package using the apt-get command:
      $ sudo apt-get install git
  1. So far, we have been running the Docker client using the sudo command, but unfortunately, we could not invoke sudo inside Jenkins because sometimes it prompts for a password. To overcome the sudo password prompt issue, we can make use of the Docker group, wherein any user who is part of the Docker group can invoke the Docker client without using the sudo command. Jenkins installation always sets up a user and group called jenkins and runs the Jenkins server using that user and group. So, we just need to add the jenkins user to the Docker group to get the Docker client working without the sudo command:
      $ sudo gpasswd -a jenkins docker
Adding user jenkins to group docker
  1. Restart the Jenkins service for the group change to take effect using the following command:
      $ sudo service jenkins restart
* Restarting Jenkins Continuous Integration Server
jenkins [ OK ]

We have set up a Jenkins environment that is now capable of automatically pulling the latest source code from the http://github.com repository, packaging it as a Docker image, and executing the prescribed test scenarios.

You are also encouraged to run Jenkins as a Docker container from the official Jenkins Docker image at https://github.com/jenkinsci/docker. This will be very good exercise also to validate your Docker container concepts from previous chapters.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset