Install Jenkins on an Azure hosted CentOS VM

In this post I will quickly run through how to install Jenkins on a Cent OS server including checking pre-requisites, installing Jenkins, opening required ports and configuring the Azure back end. This post assumes that you already have provisioned a CentOS VM within Azure to use. So log into your VM and follow these instructions:

1. Install Java (latest version) jdk by using the yum command:

Ok so the first thing to do is search for the latest version of Java available by using the following command

yum search java | grep 'java-'

This will output a list of available java packages chose the latest version. 1.8.0 was the latest when I created this post so I selected the package java-1.8.0-openjdk.x86_64. You should be able to find a similar listing with a higher version number if there is one available. Install it by copying the package name after install command

sudo yum install java-1.8.0-openjdk.x86_64

jdk install

2. Check that it has installed correctly using the command:

java version

jdk check

This should match the version number that you just installed

3. Add JAVA_HOME AND JRE_HOME to the /etc/profile (ensure to update the version number if applicable)

export JAVA_HOME=/usr/lib/jvm/jre-1.8.0-openjdk
export JRE_HOME=/usr/lib/jvm/jre

4. Check this woks using the following command

source /etc/profile
echo $JAVA_HOME
echo $JRE_HOME

It should display something like the following

check java home

5. Ok so now lets install Jenkins using the following commands:

sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo

sudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key

sudo yum install jenkins

jenkins install

6. Now we have Jenkins installed we should instruct it to start every time the virtual machine starts up. This will make things easier in future.

sudo systemctl start jenkins.service

sudo systemctl enable jenkins.service

jenkins service

7. We now need to open a firewall port within CentOS to enable us to open the Jenkins console on a web browser. The default port is 8080. CentOS 7 uses FirewallD which is different to previous CentOS versions so if you have an error at this step that could be the problem.

Use the following command to open the port:

sudo firewall-cmd --zone=public --permanent --add-port=8080/tcp
sudo firewall-cmd --reload

firewall rules

If you encounter the error that FirewallD is not running then you should instruct it to start automatically when the VM starts like we did with Jenkins.

firewall not running

The command is:

sudo systemctl enable firewalld
sudo systemctl start firewalld

firewall service

You can then try adding the firewall rule again.

8. Now go to a web browser and try and open YOUR_SERVER_IP:8080 which should bring you to a Jenkins homepage.

9 IT DIDN’T WORK! On Azure if you get the page below then you still need to open the port through security rules in the azure web portal.

network error

10. On the Azure web portal find the network security group for the VM you have hosted Jenkins on either through all resources if you know which it is, or by going to the VM list, selecting your VM, Selecting Network Interfaces, selecting the Network interface and then selecting the network security group.

NIC.png

11. Click on the group to add the required inbound rule:

inbound rule

12. Click Inbound security rules, select ‘Add’ and input the following rule

add inbound rule

13. Now if you open YOUR_SERVER_IP:8080 in a browser you should see the Jenkins unlock page. Follow the instructions to get the unlock password.

unlock jenkins14. You will then be prompted through the rest of the configuration in the browser session. I recommend just installing the recommended plugins unless you have a set of defined plugins in mind.

15. Create an Admin account for yourself once prompted.

That’s it you have successfully installed Jenkins!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s