23 Jul, 2018

Setting up Jenkins on Ubuntu dedicated server

As a developer, often you are blocked by repetitive tasks that need be done. This is something that can become frustrating, but luckly we have some tools to help. In the following lines we will talk about Jenkins, an automation server written in Java.


  • Your Ubuntu has a public IP address
  • Your sudo username is: admin
  • Your host is: jenkins.example.com
  • You have a cname DNS entry for every subdomain of jenkins.example.com pointing to itself.

The setup

Please note that there are commands which are not mandatory and everything can be adapted to the needs of your system (e.g. You might choose not to use nginx)

Sudo user

  • sudo apt-get update
  • adduser admin
  • usermod -aG sudo admin
  • sudo passwd -l root
  • su - admin

The locale

  • locale
  • sudo apt-get install language-pack-en-base
  • sudo dpkg-reconfigure locales


If using digitalocean, swap is not recommended.

  • sudo swapon --show
  • sudo fallocate -l 4G /swapfile
  • ls -lh /swapfile
  • sudo chmod 600 /swapfile
  • ls -lh /swapfile
  • sudo mkswap /swapfile
  • sudo swapon /swapfile
  • sudo swapon --show

Make swap permanent

  • sudo nano /etc/fstab
    and add at the end:
    /swapfile none swap sw 0 0


  • sudo ufw allow 8080
  • sudo ufw allow OpenSSH
  • sudo ufw enable

Setup java

  • sudo apt-get install default-jre


  • sudo apt-get install jenkins
  • sudo systemctl start jenkins
  • sudo systemctl status jenkins
  • sudo nano /var/lib/jenkins/secrets/initialAdminPassword
  • Access http://jenkins.example.com:8080/ to finish setup.

“Package ‘jenkins’ has no installation candidate”

“ubuntu 18.04 jenkins found an incorrect java version”


    • sudo apt-get update
    • sudo apt-get install nginx
    • sudo ufw allow 'Nginx HTTP'
    • sudo add-apt-repository ppa:certbot/certbot
    • sudo apt-get update
    • sudo apt-get install python-certbot-nginx
    • sudo nano /etc/nginx/sites-available/default
      • replace server_name _ with server_name jenkins.example.com www.jenkins.example.com;
    • sudo nginx -t
    • sudo systemctl reload nginx
  • sudo ufw allow 'Nginx Full'
  • sudo ufw delete allow 'Nginx HTTP'
  • sudo certbot --nginx -d jenkins.example.com -d www.jenkins.example.com
  • Choose redirect all traffic to https://

Use Jenkins with ssl nginx

  • sudo nano /etc/nginx/sites-available/default
    • find try_files $uri $uri/ =404;
    • replace with:
  • sudo nano /etc/default/jenkins
    • find
      JENKINS_ARGS="--webroot=/var/cache/$NAME/war --httpPort=$HTTP_PORT"
    • replace with:
      JENKINS_ARGS="--webroot=/var/cache/$NAME/war --httpPort=$HTTP_PORT --httpListenAddress="
  • sudo systemctl restart jenkins
  • sudo systemctl restart nginx
  • Go to: https://jenkins.example.com and choose: Manage jenkins > Configure system and update Jenkins location > Jenkins URL to https://jenkins.example.com.


For a better UI/UX experience, you could install the BlueOcean plugin, from the jenkins available plugins.