Configure Ubuntu headless server 16.x as TeamCity Build Agent to use Cake

Setting up a cross platform DevOps environment for Core applications, we will learn how to configure a headless ubuntu server to act as TeamCity BuildAgent to use Cake to build Core applications.

This guide assumes you have configured a ubuntu 16.X headless server with .net core CLI.

Check out Install .net core on ubuntu 16.x headless server

Install the prequisites

You will also need install Mono-Complete

Mono is a platform for running and developing applications based on the ecma/iso standards. mono is an open source effort led by xamarin. mono provides a complete clr (common language runtime) including compiler and runtime, which can produce and execute cil (common intermediate language) bytecode (aka assemblies), and a class library.

Install Mono on Ubuntu 16.x

Although not strictly necessary to build .net core applications we will also install Mono on the server to facilitate the building of other .net framework applications.

Install mono-complete via the terminal

Test Cake Build on the server

In order to test that we have the server configured correctly We can now try out Cake following instructions from – Getting Started example.

Install the Bootstrapper

Create a Cake script

We will use nano to create the file

Copy & Paste the sample code

If you want more information about how to write a cake build script.

Check out How to write a Cake Build script for core project

Change permission on

Execute the Build

We should see the following result indicating that we were able to successfully build a project using Cake on the server.

Configure as Build Agent

We are going to be using this server as an external build agent for use with TeamCity. In my scenario I have TeamCity installed on a seperate ubuntu server.

We need to install a few more pre-requisites to enable this.

Install Unzip

Install Java JDK & JRE

TeamCity is a Java based application therefore all build agents etc have been developed using Java.

  1. Open a Terminal window , in my case from a ubuntu box CTRL + ALT + T
  2. Add a reference to the Oracle PPA then update your package repository

  3. Install Oracle JDK 8

  4. Check your Java Version

    The version information returned should be similar too:

  5. Configure JAVA_HOME environment variable
    To find out where Java was installed

    Copy the path from your preferred installation and then open /etc/environment using nano or another text editor.

    At the end of the file on a new line paste the following or whatever your java installation path is

    Refresh your terminal windows source

    We can now test the environment variable has been set

Configure using Agent Push from TeamCity

We can now configure this server as BuildAgent from within TeamCity utilizing the Agent Push functionality.

Set Agent to AUto Start

Paste the following code, change the name of the USER variable to whatever username required to run the the script. In my case I have created an agentuser account. You may need to change this value to suit your environment.

Setting up and Running Additional Build Agents

Provide the sufficient permissions for the file to execute

Add it to the start up process

Reference Sites

Gary Woodfine

Freelance Full Stack Developer at
Helps businesses by improving their technical proficiencies and eliminating waste from the software development pipelines.

A unique background as business owner, marketing, software development and business development ensures that he can offer the optimum business consultancy services across a wide spectrum of business challenges.

Affiliate Disclaimer

Disclosure: Please note that some of the links included in the blog posts are affiliate links, which means I will earn a commission if you decide to make a purchase.

I only include affiliate links to products, services and companies that I have personal experience and have actually used. I only recommend them because they are helpful and useful, not because of the small commissions I make if you decide to buy something.

Please do not spend any money on these products unless you feel they are relevant, suitable and will help you achieve your goals.

Buying anyone of these products and the commisions earned will not make me an overnite multi millionaire, but they will help to cover the hosting costs and compensate for the countless hours and effort I put in to create meaningful and valuable free content I provide to help others succeed.

You've also undoubtedly noticed that I also use various advertising networks - unless of of course you're using an Ad blocker, this is also an attempt to reduce my monthly deficit I experience in providing free relevant, valuable and on occassion insightful content for the benefit of others.

I only really make some money if people click on the ads, unless of course you consider 1c per 1000 impressions real money!

Bear in mind just how many impressions I need to make before I can cover my £20 hosting costs a month!

If you are using an adblocker and guilt stricken you can of course donate using any of the buttons below, but I won't be holding my breath.

Buy me a coffeeBuy me a coffee