OpenSUSE 13: Install Jenkins

This article will describe installing Jenkins running on apache2.

1 Install Jenkins

Add Jenkins repository and install Jenkins.

> sudo zypper ar -f http://pkg.jenkins-ci.org/opensuse-stable/ jenkins
> sudo zypper -n --gpg-auto-import-keys up
> sudo zypper -n in jenkins
> sudo systemctl start jenkins

Open Jenkins port which is defined as JENKINS_PORT in /etc/sysconfig/jenkins. JENKINS_PORT is 8080 by default.

> firewall_open_tcp()
{
  for t in FW_SERVICES_EXT_TCP FW_SERVICES_DMZ_TCP FW_SERVICES_INT_TCP; do
    sudo sed -e "s/^${t}=\"\(.*\)\"/${t}=\"\1 $1\"/g" \
         -i /etc/sysconfig/SuSEfirewall2
  done
  sudo systemctl restart SuSEfirewall2
}
> firewall_open_tcp 8080

Now you can access to Jenkins via below URL.

http://<server>:8080

2 Use mod_proxy

Install Apache2.

> sudo zypper -n in apache2

Add Apache2 config file for Jenkins. 8080 is JENKINS_PORT value.

> sudo su -c 'cat <<EOF > /etc/apache2/conf.d/jenkins.conf
<IfModule mod_proxy.c>
  ProxyPass           /jenkins  http://localhost:8080/jenkins
  ProxyPassReverse    /jenkins  http://localhost:8080/jenkins
  ProxyRequests       Off
  AllowEncodedSlashes NoDecode

  <Proxy http://localhost:8080/jenkins>
    Order deny,allow
    Allow from all
  </Proxy>
</IfModule>
EOF
'

Enable mod_proxy and mod_proxy_http, and restart Apache2.

> sudo a2enmod proxy
> sudo a2enmod proxy_http
> sudo systemctl restart apache2

Open Apache2 port.

> firewall_open_service()
{
  for t in FW_CONFIGURATIONS_EXT FW_CONFIGURATIONS_DMZ FW_CONFIGURATIONS_INT; do
    sudo sed -e "s/^${t}=\"\(.*\)\"/${t}=\"\1 $1\"/g" \
         -i /etc/sysconfig/SuSEfirewall2
  done
  sudo systemctl restart SuSEfirewall2
}
> firewall_open_service apache2

Add prefix option so that Jenkins knows URI.

> sudo sed -i -e \
's;JENKINS_ARGS="\(.*\)";JENKINS_ARGS="--prefix=/jenkins \1";g' \
/etc/sysconfig/jenkins
> sudo systemctl restart jenkins

Now you can access to Jenkins via below URL.

http://<server>/jenkins

If JENKINS_PORT is opened, you can access to Jenkins via below URL too. If you do not need this, close JENKINS_PORT.

http://<server>:8080/jenkins

3 Script for installing Jenkins and using mod_proxy

The following script will install Jenkins and use mod_proxy.

#!/bin/sh

firewall_open_tcp()
{
  for t in FW_SERVICES_EXT_TCP FW_SERVICES_DMZ_TCP FW_SERVICES_INT_TCP; do
    sudo sed -e "s/^${t}=\"\(.*\)\"/${t}=\"\1 $1\"/g" \
         -i /etc/sysconfig/SuSEfirewall2
  done
  sudo systemctl restart SuSEfirewall2
}

firewall_open_service()
{
  for t in FW_CONFIGURATIONS_EXT FW_CONFIGURATIONS_DMZ FW_CONFIGURATIONS_INT; do
    sudo sed -e "s/^${t}=\"\(.*\)\"/${t}=\"\1 $1\"/g" \
         -i /etc/sysconfig/SuSEfirewall2
  done
  sudo systemctl restart SuSEfirewall2
}

sudo zypper ar -f http://pkg.jenkins-ci.org/opensuse-stable/ jenkins
sudo zypper -n --gpg-auto-import-keys up
sudo zypper -n in jenkins
# Comment out if you need.
# firewall_open_tcp 8080

sudo zypper -n in apache2
sudo su -c 'cat <<EOF > /etc/apache2/conf.d/jenkins.conf
<IfModule mod_proxy.c>
  ProxyPass           /jenkins  http://localhost:8080/jenkins
  ProxyPassReverse    /jenkins  http://localhost:8080/jenkins
  ProxyRequests       Off
  AllowEncodedSlashes NoDecode

  <Proxy http://localhost:8080/jenkins>
    Order deny,allow
    Allow from all
  </Proxy>
</IfModule>
EOF
'

sudo a2enmod proxy
sudo a2enmod proxy_http
sudo systemctl restart apache2
firewall_open_service apache2

sudo sed -i -e \
     's;JENKINS_ARGS="\(.*\)";JENKINS_ARGS="--prefix=/jenkins \1";g' \
     /etc/sysconfig/jenkins
sudo systemctl start jenkins