Setup Jenkins in Ubuntu 20.04

  1. Add repository Jenkins and Install Jenkins
    1
    2
    3
    4
    $ sudo wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
    $ sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
    $ sudo apt update
    $ sudo apt install openjdk-11-jdk-headless jenkins -y
  2. Start Jenkins
    1
    2
    $ sudo systemctl enable --now jenkins
    $ sudo systemctl status jenkins
  3. Setting Up Jenkins
    1
    2
    $ sudo ss -nl |grep 8080
    $ cat /var/lib/jenkins/secrets/initialAdminPassword
  4. Edit default configuration Jenkins
    1
    2
    3
    4
    5
    6
    7
    $ sudo vim /etc/default/jenkins
    ...
    JENKINS_ARGS="--webroot=/var/cache/$NAME/war --httpPort=$HTTP_PORT --httpListenAddress=127.0.0.1"
    ...

    $ sudo systemctl restart jenkins
    $ sudo systemctl status jenkins
  5. Setup Nginx for Proxy
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    $ sudo apt install nginx certbot -y
    $ sudo systemctl stop nginx
    $ sudo certbot certonly -d jenkins.goreng.cc --register-unsafely-without-email
    $ sudo vim /etc/nginx/sites-available/jenkins.goreng.cc
    ...
    server {
    listen 443 ssl http2 ipv6only=on;
    listen [::]:443 ssl http2;
    server_name jenkins.goreng.cc;

    access_log /var/log/nginx/jenkins.access.log;
    error_log /var/log/nginx/jenkins.error.log;

    # SSL
    ssl_certificate /etc/letsencrypt/live/jenkins.goreng.cc/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/jenkins.goreng.cc/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/jenkins.goreng.cc/chain.pem;

    location / {
    include /etc/nginx/proxy_params;
    proxy_pass http://localhost:8080;
    proxy_read_timeout 90s;
    proxy_redirect http://localhost:8080 https://jenkins.goreng.cc.com;
    }
    }

    # subdomains redirect
    server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name *.jenkins.goreng.cc;

    # SSL
    ssl_certificate /etc/letsencrypt/live/jenkins.goreng.cc/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/jenkins.goreng.cc/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/jenkins.goreng.cc/chain.pem;
    return 301 https://jenkins.goreng.cc$request_uri;
    }

    # HTTP redirect
    server {
    listen 80;
    listen [::]:80;
    server_name .jenkins.goreng.cc;

    location / {
    return 301 https://jenkins.goreng.cc$request_uri;
    }
    }
    ...

    $ sudo ln -s /etc/nginx/sites-available/jenkins.goreng.cc /etc/nginx/sites-enabled/
    $ sudo systemctl start nginx
  6. Access jenkins via Browser
    1
    https://jenkins.goreng.cc