In this blog, we will set up jenkins and configure jenkins on ubuntu 16 for continuous development and continuous integration. Jenkins is a Continuous Integration server. Basically, Continuous Integration is the practice of running your tests on a non-developer machine automatically everytime someone pushes new code into the source repository.
Before we set up jenkins, you need to have java installed on your systems. Install open JDK 7 on both ubuntu machines using below commands.
Command: sudo add-apt-repository ppa:openjdk-r/ppa
Command: sudo apt-get update
Command: sudo apt-get install openjdk-7-jdk
Run below command to see if java got installed on your system.
Command: java -version
Before we can install Jenkins, we have to add the key and source list to apt. This is done in 2 steps, first we'll add the key.
wget -q -O - https://jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
Secondly, we'll create a sources list for Jenkins.
sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list'
Now, we only have to update apt's cache before we can install Jenkins
sudo apt-get update
As the cache has been updated we can proceed installing Jenkins. Note that Jenkins has a big bunch of dependencies, so it might take a few moments to install them all.
sudo apt-get install jenkins
After you have installed jenkins, open the browser and go to http://your_ip_address:8080
By default jenkins run on port 8080, my ip address is 192.168.1.33
Below command will give you the password which was needed in previous step, use it to continue.
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Now you will be asked to either install suggested plugins or select plugins to install, you need to select install suggested plugins.
Basic plugins like folders plugin, pipeline, git plugin, ant plugin, subversion plugin etc. will get installed.
Once the installation is over, you will be asked to create first admin user. Mention all the details asked and click on save and finish.
Click on start using jenkins.
Security in Jenkins
Now that Jenkins is running, go to http://your_ip_address:8080. You'll be welcomed by the default Jenkins screen.
The next step is to configure security in jenkins. Go to manage jenkins -> configure global security.
Check the option box for Enable security to bring up a group of options for this purpose. Under the Access Control section that appeared when we flagged the checkbox, select Jenkins' own user database.
Deselect the checkbox marked - Allow users to sign up, to restrict users to sign up as they wish can allow a level of openness that can potentially be dangerous.
Under Authorization, select the Matrix-based security option. You'll see a user named Anonymous is already present. An anonymous user is anybody from anywhere, even when they're not logged in, which is why by default the anonymous user has no abilities. Since this is the initial setup of the Jenkins instance, you must give this user full permissions by clicking on all the checkboxes.
Next, use the User/group to add input field to specify a new user, enter a username in lowercase and press Add. Give the new user all permissions the same way you did for the anonymous user. This essentially sets up a new administrator.
When you're done, press Apply and then Save.
Now go to Manage Jenkins -> Configure Global Security and scroll down to the security matrix. Remove all the permissions from anonymous as you have already created a new admin user now, after that click Apply and Save. Your new user will now be the only user with access to Jenkins.
If you turned off the automatic sign up earlier, you might need to manually create additional new users. Here's how:
- Go to Manage Jenkins page -> Manage Users.
- Click on Create User.
- Enter the information for the new user, and click Sign up.
- Give the permission to the user.
Once Jenkins is installed, minimally configured, and reasonably secured, it's time to make it fit your needs.
Jenkins act as a middleman for software projects and provide a lot of plugins to do so. Plugins are add-ons that allow
From the main left hand side menu in Jenkins, click Manage Jenkins -> Manage Plugins.
You will see many plugins are already installed but need updating – you can perform this easily by selecting the plugins you want to update and clicking the button at the bottom.
If you click on Available from this page, you will be taken to a list of available plugins. You man select the plugins you need depending on the project.
Once you have selected those plugins you want to install on the Available tab, click the button marked Download now and install after restart.
Below are few details on different types of plugins present:
- Source control: Git, SVN, and Team Foundation Server are some of the more common source control systems. All three of these have plugins in the Jenkins list, and others exist for less common systems as well. If you don't know what source control is, you should really learn about it and start incorporating it in your projects. Be sure to install the plugin for your source control system, so Jenkins can run builds through it and control tests.
- Copy Artifact: This plugin allows you to copy components between projects, easing the pain of setting up similar projects if you lack a true dependency manager.
- Throttle Concurrent Builds: If you have multiple builds running which might introduce a conflict (due to shared resources, etc), this will easily allow you to alleviate this concern.
- Dependency Graph Viewer: A nifty plugin providing a graphic representation of your project dependencies.
- Jenkins Disk Usage: Jenkins may be fairly lightweight, but the same can't always be said for the projects with which it integrates. This plugin lets you identify how much of your computing resources any of your jobs are consuming.
- Build tools: If your project is large, you probably use a build manager, such as Maven or Ant. Jenkins provides plugins for many of these, both to link in their basic functionality and to add control for individual build steps, projection configuration, and many other aspects of your builds.
- Reporting: While Jenkins provides its own reports, you can extend this functionality to many reporting tools.
- Additional Authentication: If the default Jenkins abilities for security don't suite you, there are plenty of plugins to extend this – from Google logins, to active directory, to simple modifications of the existing security.
Next step is to create a job and build it, so let's go ahead and do that.
From the Jenkins interface home, select New Item. Enter a name and select Freestyle project, click on ok.
Now you need to specify the job configuration. On this configuration page you also have the option to add build step, select execute shell.
This will provide you with a text box in which you can add whatever commands you need . We'll use this section to run a script. We will use a very basic script i.e. just to print something.
Save the project, and you'll be taken to its project overview page. Here you can see information about the project, including its built history.
Click on build now and your will see a build has started, you can see a blue bubble on the screen.
To see more information, click on that build in the build history area, whereupon you’ll be taken to a page with an overview of the build information:
Now click on console output so see the complete information of the build. You can see in the console output that our script executed successfully, and it has printed what it was asked to. Hence, you have successfully built the jenkins job.
We have successfully installed and configured jenkins. It is able to create builds and run them. With the help of Jenkins, we were able to do continuous deployment integration on ubuntu 16.