Configure Ubuntu headless server 16.x as TeamCity Build Agent to use Cake
Setting up a cross platform DevOps environment for ASP.net Core applications, we will learn how to configure a headless ubuntu server to act as TeamCity BuildAgent to use Cake to build ASP.net Core applications.
Install the prequisites
You will also need install
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.
mono-complete via the terminal
sudo apt install mono-complete -y
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 CakeBuild.net – Getting Started example.
Install the Bootstrapper
curl -Lsfo build.sh http://cakebuild.net/download/bootstrapper/linux
Create a Cake script
We will use
nano to create the file
Copy & Paste the sample code
var target = Argument("target", "Default");
Change permission on
chmod +x build.sh
Execute the Build
We should see the following result indicating that we were able to successfully build a project using Cake on the server.
All packages listed in /home/gary/tools/packages.config are already installed.
Analyzing build script...
Processing build script...
Compiling build script...
Executing task: Default
Finished executing task: Default
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.
sudo apt install unzip
Install Java JDK & JRE
TeamCity is a Java based application therefore all build agents etc have been developed using Java.
- Open a Terminal window , in my case from a ubuntu box
CTRL+ ALT+ T
- Add a reference to the Oracle PPA then update your package repository12sudo add-apt-repository ppa:webupd8team/javasudo apt-get update
- Install Oracle JDK 81sudo apt-get install oracle-java8-installer
- Check your Java Version1java -version
The version information returned should be similar too:123java version "1.8.0_121"Java(TM) SE Runtime Environment (build 1.8.0_121-b13)Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
- Configure JAVA_HOME environment variable
To find out where Java was installed1sudo update-alternatives --config java
Copy the path from your preferred installation and then open
nanoor another text editor.1sudo nano /etc/environment
At the end of the file on a new line paste the following or whatever your java installation path is1JAVA_HOME="/usr/lib/jvm/java-8-oracle"
Refresh your terminal windows source1source /etc/environment
We can now test the environment variable has been set1echo $JAVA_HOME
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
sudo nano /etc/init.d/teamcity
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.
### BEGIN INIT INFO
# Provides: TeamCity Build Agent
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start build agent daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
#Provide the correct user name:
case "$1" in
su - $USER -c "cd BuildAgent/bin ; ./agent.sh start"
su - $USER -c "cd BuildAgent/bin ; ./agent.sh stop"
echo "usage start/stop"
Provide the sufficient permissions for the file to execute
sudo chmod +x /etc/init.d/teamcity
Add it to the start up process
sudo update-rc.d teamcity defaults
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.