1. Home
  2. Linux
  3. Ubuntu
  4. How to Install and Configure GoCD on Ubuntu 16.04

How to Install and Configure GoCD on Ubuntu 16.04

How to Install and Configure GoCD on Ubuntu 16.04
How to Install and Configure GoCD on Ubuntu 16.04

GoCD is an open source continuous delivery and automation system. It allows you to model complex workflows using its parallel and sequential execution. Its value stream map allows you to easily visualize a complex workflow with ease. GoCD lets you easily compare two builds and deploy any version of the application you want. The GoCD ecosystem consists of the GoCD server and the GoCD agent. GoCD is responsible for controlling everything from running the web-based user interface to managing and providing jobs to the agent. Go agents are responsible for running the jobs and deployments.


  • A DreamVPS Ubuntu 16.04 server instance with at least 2GB RAM.
  • A sudo user.
  • A domain name pointed towards the server.

For this tutorial, we will be using ‘′ as the public IP address and ‘gocd.example.com’ as the domain name pointed towards the ‘DreamVPS’ instance. Please make sure to replace all occurrences of the example domain name and IP address with your actual one.
Update your base system using the guide How to Update Ubuntu 16.04. Once your system has been updated, proceed to install Java.

Install Java

GoCD requires Java version 8; it supports both Oracle Java and OpenJDK. Add the Ubuntu repository for Oracle Java 8.

sudo add-apt-repository --yes ppa:webupd8team/java
sudo apt update

Install Oracle Java.

sudo apt -y install oracle-java8-installer

Check the version.

java -version

You will see the following output.

user@dreamvps:~$ java -version
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

Set the default path for Java by installing the following package.

sudo apt -y install oracle-java8-set-default

You can verify if ‘JAVA_HOME’ is set by running the below.


You should see the following.

user@dreamvps:~$ echo $JAVA_HOME

If you see no output at all, you will need to log out from the current shell and log back in.

Install GoCD

Install GoCD’s official repository into the system.

echo "deb https://download.gocd.org /" | sudo tee /etc/apt/sources.list.d/gocd.list
curl https://download.gocd.org/GOCD-GPG-KEY.asc | sudo apt-key add -
sudo apt update

Install the GoCD server on your system.

sudo apt install -y go-server

Start GoCD and enable it to automatically start at boot time.

sudo systemctl start go-server
sudo systemctl enable go-server

Before you access the GoCD dashboard, create a new directory to store the artifacts. Artifacts can be stored on the same disk on which the operating system and the applications are installed. Alternatively, you can use a dedicated disk or block storage drive to store the artifacts.
If you wish to use the same disk to store the artifacts, simply create a new directory and provide the ownership to the GoCD user.

sudo mkdir /opt/artifacts
sudo chown -R go:go /opt/artifacts


Configure Block Storage

The GoCD software recommends that you use an additional partition or drive to store the artifacts. The disk space decreases over time when new artifacts are continuously generated and, in a continuous integration and delivery platform, artifacts are generated very often. At some stage, your system will run out of free disk space and the services running on your system will fail. To overcome this issue, you can attach a new DreamVPS block storage drive to store the artifacts.
If you still wish to go with the storage of artifacts on the same drive, skip to the ‘Configure GoCD’ section.
Deploy a new block storage drive and attach it to your GoCD server instance. Now create a new partition on the block storage device.

sudo parted -s /dev/vdb mklabel gpt
sudo parted -s /dev/vdb unit mib mkpart primary 0% 100%

Create the file system on the new disk.

sudo mkfs.ext4 /dev/vdb1

Mount the block storage drive.

sudo mkdir /mnt/artifacts
sudo cp /etc/fstab /etc/fstab.backup
echo "
/dev/vdb1 /mnt/artifacts ext4 defaults,noatime 0 0" | sudo tee -a /etc/fstab
sudo mount /mnt/artifacts

Now, run ‘df’ and you will see the new block storage drive mounted on ‘/mnt/artifacts’.

[user@dreamvps ~]$ df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/vda1       20616252 6313892  13237464  33% /
/dev/vdb1       10188052   36888   9610596   1% /mnt/artifacts

Provide ownership of the directory to the GoCD user.

sudo chown -R go:go /mnt/artifacts

Configure GoCD

Now you can access the GoCD dashboard on ‘′. To access the GoCD dashboard on a secured connection, access ‘′. You will get an error showing that the certificates are not valid. This error can be safely ignored as the certificates are self-signed. For security purposes, you should always use the dashboard over a secured connection.
Before you set up a new pipeline, navigate to ‘Admin >> Server Configuration’ from the top navigation bar.
Input the URL to your unsecured site in the ‘Site URL’ field and the secured site in the ‘Secure Site URL’ field.

Next, provide your SMTP server details to send email notifications from GoCD.

Finally, provide the path to the location where you wish to store the artifacts. If you have chosen to store the artifacts on the same disk as the operating system, enter ‘/opt/artifacts’. However, if you have chosen to attach a block storage drive, then you can enter ‘/mnt/artifacts’.
You can also configure GoCD to auto-delete the old artifacts. Configure the next option according to your disk size. However, the auto-delete option does not take a backup of your old artifacts. To manually take a backup and then delete the old artifacts, disable auto delete by choosing the ‘Never’ option for the ‘Auto delete old artifacts’ section.

You will have to restart the GoCD server so that the new changes are applied.

sudo systemctl restart go-server


Setup Authentication

By default, the GoCD dashboard is not configured to use any kind of authentication, however, it supports authentication using a password file and LDAP.
In this tutorial, we will show you how to set up password-based authentication.
Note: Setting up authentication is an optional step, however, it is strongly recommended for public facing servers such as DreamVPS

Install Apache tools so that you can use the ‘htpasswd’ command to create an encrypted password file.

sudo apt -y install apache2-utils

Create a password file with the ‘htpasswd’ command using ‘Bcrypt’ encryption.

sudo htpasswd -B -c /etc/go/passwd_auth goadmin

Provide the password for the user twice. You should see the following output.

[user@dreamvps ~]$ sudo htpasswd -B -c /etc/go/passwd_auth goadmin

New password:
Re-type new password:
Adding password for user goadmin
You can add as many users as you want using the same command above but by remove the ‘-c’ option. The ‘-c’ option will replace the existing file, thus replacing old users with the new user.

sudo htpasswd -B /etc/go/passwd_auth gouser1

Now that we have created the password file, access the GoCD dashboard again. Navigate to ‘Admin >> Security >> Authorization Configurations’ from the top navigation bar.
Click on the ‘Add’ button and provide any ID.
Choose ‘Password File Authentication Plugin for GoCD’ for the plugin ID and direct the path to the password file.
Now click on the ‘Check Connection’ button to verify that GoCD can use the password file for authentication.
Finally, save the authentication method. Reload the dashboard and it will automatically log you out. You will see a login screen now. Log in using the credentials created earlier.
You will need to promote the administrator user manually, otherwise all the users will have administrator privileges. Navigate to ‘Admin >> User Summary’ from the top navigation bar.
After this, select the admin user you have created and click on the ‘Roles’ drop-down. Promote the user to the only administrator by selecting the ‘Go System Administrator’ checkbox.
To add the users in GoCD created in the password file, click on the ‘ADD’ button and search for the user to add them. Users are also automatically added to the GoCD dashboard on their first login. For users to log in, they must be added to the password file you have created earlier.

Securing GoCD with Let’s Encrypt SSL

By default, GoCD listens to ports 8153 and 8154 on secure connections. Though port 8154 provides a secure connection to the application, it also displays browser errors as it uses a self-signed certificate.
In this section of the tutorial, we will show you how to install and secure Nginx with a Let’s Encrypt free SSL certificate. The Nginx web server will work as a reverse proxy to forward the incoming requests to GoCD’s HTTP endpoint.
Install Nginx.

sudo apt -y install nginx

Start Nginx and enable it to automatically start at boot time.

sudo systemctl start nginx
sudo systemctl enable nginx

Add the Certbot repository.

sudo add-apt-repository --yes ppa:certbot/certbot
sudo apt-get update

Install Certbot, the client application for Let’s Encrypt CA.

sudo apt -y install certbot

Note: To obtain certificates from Let’s Encrypt CA, the domain for which the certificates are to be generated must be pointed towards the server. If not, make the necessary changes to the DNS records of the domain and wait for the DNS to propagate before making the certificate request again. Certbot checks the domain authority before providing the certificates.
Generate the SSL certificates.

sudo certbot certonly --webroot -w /var/www/html -d gocd.example.com

The generated certificates are likely to be stored in ‘/etc/letsencrypt/live/gocd.example.com/’. The SSL certificate will be stored as ‘fullchain.pem’ and the private key will be stored as ‘privkey.pem’.
Let’s Encrypt certificates expire in 90 days, so it is recommended to set up auto-renewal of the certificates using cron jobs.
Open the cron job file.

sudo crontab -e

Add the following line to the end of the file.

30 5 * * * /usr/bin/certbot renew --quiet

The above cron job will run every day at 5:30 AM. If the certificate is due for expiration, it will automatically renew.
Create a new configuration file for the GoCD web interface.

sudo nano /etc/nginx/sites-available/gocd

Fill in the file with the information below.

upstream gocd {
server {
    listen 80;
    server_name gocd.example.com;
    return 301 https://$host$request_uri;
server {
    listen 443;
    server_name gocd.example.com;
    ssl_certificate           /etc/letsencrypt/live/gocd.example.com/fullchain.pem;
    ssl_certificate_key       /etc/letsencrypt/live/gocd.example.com/privkey.pem;
    ssl on;
    ssl_session_cache  builtin:1000  shared:SSL:10m;
    ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
    ssl_prefer_server_ciphers on;
    access_log  /var/log/nginx/gocd.access.log;
location / {
        proxy_pass http://gocd;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_redirect off;
location /go {
    proxy_pass http://gocd/go;
    proxy_http_version 1.1;
    proxy_set_header Upgrade websocket;
    proxy_set_header Connection upgrade;
    proxy_read_timeout 86400;

Activate the configuration file.

sudo ln -s /etc/nginx/sites-available/gocd /etc/nginx/sites-enabled/gocd

Restart the Nginx web server to implement the change in configuration.

sudo systemctl restart nginx

Now you can access the GoCD dashboard at ‘https://gocd.example.com’. Log into your dashboard using the administrator credentials and navigate to ‘Admin >> Server Configuration’ from the top navigation bar.

Set the ‘Site URL’ and ‘Secure Site URL’ to ‘https://gocd.example.com’.

Installing GoCD Agent

In the GoCD continuous integration environment, GoCD agents are the workers that are responsible for the execution of all the tasks. When a change in the source is detected, the pipeline is triggered and the jobs are assigned to available workers for execution. The agent then executes the task and reports the final status after execution.
To run a pipeline, at least one agent must to be configured. Proceed to install the GoCD agent on the GoCD server.
Since you have already imported the GoCD repository into the server, you can directly install Go Agent.

sudo apt install -y go-agent

Now, start the GoCD server and enable it to automatically start at boot time.

sudo systemctl start go-agent
sudo systemctl enable go-agent

The GoCD agent running on the localhost is automatically enabled when detected.

Updated on December 23, 2018

Was this article helpful?

Related Articles

Leave a Comment

[apsl-login-lite login_text='Please login with a social account']