Setup – Apache and Jenkins
Overview
For those that don’t know yet, Jenkins is what use to be known by the name Hudson. So, if you think this article looks a lot like my “Setup – Apache and Hudson” article, it’s probably because it is. So, even though the steps in that article will still work for the install of Hudson, you should probably embrace the change of name and move your installs to the new “Jenkins” name 🙂
This is a quick and easy tutorial to get up and running quickly with a complete environment as set out below. What will be covered is how to easily get up and running in the quickest, easiest manner. What I’ll be going through are as follows:
- Pre-requisites
- Downloading and installing Jenkins
- Downloading & installing Apache
- Configuring Apache and Jenkins
- Move Jenkins Install to Another Folder
- Conclusion
Note that I’m installing and running these environments on a VirtualBox VM running Ubuntu version 3.2.10. If you would like to know how to set up the same environment you can refer to my other article called “Setup – Ruby & RVM”.
Pre-requisites
I would strongly advise you to head over to my article called “Setup – Requirements” and running through the list there from top to bottom. I’ll be keeping that article up to date with some new packages that you’ll need to have a complete Development, Build and Production environment running on Ubuntu.
Downloading and installing Jenkins
When installing Jenkins I like to set it up so it automatically pulls the latest versions as and when the stable releases gets released. This is a very simple set up as follows. You’ll want to get the key by opening up a Terminal Window and running the following command:
wget -q -O – http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add –
This will download a “key” file to your “/tmp/” folder, add it to your system keys and remove it from your “/tmp” folder. Now that the key has been added to your system you can go ahead and download Jenkins by running the following command:
wget -O /tmp/jenkins.deb http://pkg.jenkins-ci.org/debian/binary/jenkins_1.398_all.deb
This will download Jenkins to the “/tmp/” folder as the file “jenkins.deb”, which will then allow us to go and depackage and install it by running the following command:
sudo dpkg –install /tmp/jenkins.deb
Once this is completed, you have Jenkins up and running and you should be able to browse to your newly created Jenkins site at:
That’s it for getting Jenkins up and running. If you were wondering where Jenkins is installed, you should find it under “/etc/default/Jenkins/” and the Jenkins logs can be found under “/var/log/Jenkins/”. To start Jenkins you can run:
sudo /etc/init.d/jenkins start
And to stop it you can run:
sudo /etc/init.d/jenkins stop
One last thing on this; in future you can simply run the following command if you would like to update Jenkins:
apt-get update; apt-get install Jenkins
In the next section it gets a bit trickier when we want to run Jenkins under Apache 2 over port 80 so we can get the nicer URL of:
Downloading and installing Apache
To get the nice URL you saw in the previous section you’ll first have to edit the file “/etc/default/jenkins” file by adding “–prefix=/jenkins” to the “JENKINS_ARGS” section of the file. Once that’s been done you should restart Jenkins by running the following command:
sudo /etc/init.d/jenkins force-reload
If you get the exception as follows:
“* Restarting Jenkins Continuous Integration Server jenkins
The selected http port (8080) seems to be in use by another program
Please select another port to use for Jenkins”
Then you can run the above commands to stop and start Jenkins. This should resolve the issue and it seems to be a known bug inside Jenkins. Now we can move onto the Apache installation and configuration section. First you have to download and install by running this command:
sudo apt-get install apache2
That’s fairly straightforward to do… Once you have Apache installed you should also install the following package:
sudo apt-get install libapache2-mod-proxy-html
This will install the proxy libraries necessary to enable us to route all calls coming into our nice URL to the Jenkins server still running on port 8080. Once you have this package installed you should run the following two commands:
sudo a2enmod proxy
And you’ll also need to enable the http proxy by running this command:
sudo a2enmod proxy_http
Once these are enabled I would suggest that you also disable the root domain by running the following command:
sudo a2dissite 000-default
The next step would be to change the Apache configuration to point to your new Jenkins Build Server. To do this you can run:
sudo nano /etc/apache2/apache2.conf
When the file opens you should add the following to the bottom of the file:
ServerName localhost:8080
Now you’ll need to create a new Virtual Host for Apache to serve. You do this by making a “jenkins” file by running the following command:
sudo touch /etc/apache2/sites-available/jenkins
You should now edit the file by running:
sudo nano /etc/apache2/sites-available/jenkins
When the file is open you should add the following to it:
<VirtualHost *:80>
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
ProxyRequests Off
# Local reverse proxy authorization override
# Most unix distribution deny proxy by default
# (ie /etc/apache2/mods-enabled/proxy.conf in Ubuntu)
<Proxy http://localhost:8080/*>
Order deny,allow
Allow from all
</Proxy>
</VirtualHost>
The final step in this configuration is to enable Jenkins and to restart Apache. You can enable Jenkins by running the following command:
sudo a2ensite jenkins
Now that you have Apache installed and running and you’ve enabled it for proxy capabilities you should restart it by running the command as follows:
sudo /etc/init.d/apache2 restart
You can also restart Apache by running the stop and start commands separately by running the following two lines on Terminal:
Stopping Apache
sudo /etc/init.d/apache2 stop
Starting Apache
sudo /etc/init.d/apache2 start
That’s it… 🙂 Now you can test that your Apache setup worked by simply opening up a browser and going to http://localhost/ . If you see a big “It works”, then I guess it’s working. If not, well start over 🙂 Just kidding, but good luck 🙂
If you would like to see if the pretty URL we wanted works then you can just go to:
If it works, that’s great 🙂 Pat yourself on the back, go outside, have a smoke and if you’re not at work have a beer 🙂
Move Jenkins Install to Another Folder
In some cases you may want to change where Jenkins are installed. To do this, simply stop the Jenkins service by running the following command:
sudo /etc/init.d/jenkins stop
Then move the contents of your Jenkins install by executing the following command:
mv -f $JENKINS_HOME/* [path]
Now that you have this done, you should update the JENKINS_HOME environment variable by running the following command:
export JENKINS_HOME=[path]
You should also add this line at the end of your “~/.profile” file. Finally you should start Jenkins again by running the following command:
sudo /etc/init.d/jenkins start
Conclusion
Now that you have the Apache and Jenkins configuration up and running you’ll be able to do quite a few things, but in my case I’m trying to reach for the ultimate goal of having a CI environment, running at regular intervals pulling the new source from my Git repository, building it, running tests, deploying it to my Dev Integration servers after versioning my source and allowing our QA and Operations guys to pull whichever version they want when they want it while having full visibility to the stakeholders on the projects my team and I are working on…
I hope you enjoy the Jenkins environment and the capabilities it gives you as much as I’m going to enjoy it. I’ll keep you posted on how I do the other things in future articles…!!!! 🙂
I know Apache supports CGI-scripts. Can I access CGI-scripts from within jenkins? What is the problem with Tomcat-CGI with Jenkins?
Hi Cees,
As far as I know you can do anything from Jenkins as long as you can do the same on the host OS. As far as CGI scripts goes, I wouldn’t know where to start trying to test it seeing that I haven’t played with CGI in about 10 years and I certainly didn’t try to set it up as a Build Item 🙂 I would love to get your feedback when you do get it up and running so we can share it with those that are interested 🙂
Good luck.
Wow, that’s what I was searching for, what a material! present here at this blog, thanks admin of this website.