Skip to content

Instantly share code, notes, and snippets.

@technoir42
Last active March 31, 2017 11:35
Show Gist options
  • Save technoir42/2e7fa66d20f5a05a3409 to your computer and use it in GitHub Desktop.
Save technoir42/2e7fa66d20f5a05a3409 to your computer and use it in GitHub Desktop.

#Installing TeamCity for building Android projects

##Requirements

  • MySQL
  • JDK 1.7
  • 32-bit libstdc++ zlib.i686

##Install JDK

#CentOS:
yum install java-1.7.0-openjdk
yum install java-1.7.0-openjdk-devel

#Ubuntu:
apt-get install openjdk-7-jdk

Create /etc/profile.d/java.sh

#CentOS:
export JAVA_HOME=/usr/lib/jvm/jre-1.7.0-openjdk.x86_64

#Ubuntu:
export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64

##Install MySQL server

#CentOS:
yum install mysql-server
chkconfig mysqld on
service mysqld start

#Ubuntu:
apt-get install mysql-server

Edit /etc/my.cnf

[mysqld]
bind-address=localhost
(for MySQL 5.1) default-storage-engine=innodb

##Create user

useradd -r -m teamcity
passwd teamcity

##Install TeamCity

cd /opt
wget http://download.jetbrains.com/teamcity/TeamCity-8.1.4.tar.gz
tar xf TeamCity-8.1.4.tar.gz
chown -R teamcity:teamcity TeamCity

##Create database

mysql
create database teamcity default charset utf8;
grant all privileges on teamcity.* to teamcity@localhost identified by 'teamcity';

##Install MySQL Connector

cd /opt/TeamCity/.BuildServer
wget http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.34.tar.gz
tar xf mysql-connector-java-5.1.34.tar.gz
cp mysql-connector-java-5.1.34/mysql-connector-java-5.1.34-bin.jar lib/jdbc/

##Install PostgreSQL Connector (optional)

cd /opt/TeamCity/.BuildServer
wget http://jdbc.postgresql.org/download/postgresql-9.3-1101.jdbc41.jar
mv postgresql-9.3-1101.jdbc41.jar lib/jdbc/

##Configure service

Create /etc/init.d/teamcity

#!/bin/bash
### BEGIN INIT INFO
# Provides:          teamcity
# Required-Start:    $local_fs
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: TeamCity
# Description:       TeamCity
### END INIT INFO

TEAMCITY_USER=teamcity
TEAMCITY_DIR=/opt/TeamCity/
TEAMCITY_PATH=$TEAMCITY_DIR/bin/teamcity-server.sh
TEAMCITY_DATA_DIR=$TEAMCITY_DIR/.BuildServer

case $1 in
    start)
	    su - $TEAMCITY_USER -c "TEAMCITY_DATA_PATH=$TEAMCITY_DATA_DIR $TEAMCITY_PATH start"
	    ;;
    stop)
	    su - $TEAMCITY_USER -c "TEAMCITY_DATA_PATH=$TEAMCITY_DATA_DIR $TEAMCITY_PATH stop"
	    ;;
    *)
	    echo "Usage: $0 {start|stop}"
	    exit 1
	    ;;
esac

exit 0
#CentOS:
chmod +x teamcity
chkconfig --add teamcity
chkconfig teamcity on
service teamcity start

#Ubuntu:
chmod +x teamcity
update-rc.d teamcity defaults
service teamcity start

##Install build agent

Make sure that TeamCity is up and running.

cd /opt
mkdir TeamCity-BuildAgent && cd TeamCity-BuildAgent
wget http://localhost:8111/update/buildAgent.zip
unzip buildAgent.zip
chmod +x bin/*.sh
cp conf/buildAgent.dist.properties conf/buildAgent.properties
chown -R teamcity:teamcity /opt/TeamCity-BuildAgent

Edit /opt/TeamCity-BuildAgent/conf/buildAgent.properties:

## The address of the TeamCity server. The same as is used to open TeamCity web interface in the browser.
serverUrl=http://localhost:8111/

Create /etc/init.d/teamcity-agent

#!/bin/bash
### BEGIN INIT INFO
# Provides:          teamcity-agent
# Required-Start:    $local_fs
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: TeamCity Build Agent
# Description:       TeamCity Build Agent
### END INIT INFO

TEAMCITY_AGENT_USER=teamcity
TEAMCITY_AGENT_DIR=/opt/TeamCity-BuildAgent
TEAMCITY_AGENT_PATH=$TEAMCITY_AGENT_DIR/bin/agent.sh

case $1 in
    start)
	    su - $TEAMCITY_AGENT_USER -c "$TEAMCITY_AGENT_PATH start"
	    ;;
    stop)
	    su - $TEAMCITY_AGENT_USER -c "$TEAMCITY_AGENT_PATH stop"
	    ;;
    *)
	    echo "Usage: $0 {start|stop}"
	    exit 1
	    ;;
esac

exit 0
#CentOS:
chmod +x teamcity-agent
chkconfig --add teamcity-agent
chkconfig teamcity-agent on
service teamcity-agent start

#Ubuntu:
chmod +x teamcity-agent
update-rc.d teamcity-agent defaults
service teamcity-agent start

##Android SDK

cd /opt
wget http://dl.google.com/android/android-sdk_r24-linux.tgz
tar xf android-sdk_r24-linux.tgz
chown -R teamcity:teamcity android-sdk-linux

Create /etc/profile.d/android.sh

export ANDROID_HOME=/opt/android-sdk-linux
PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

Update Android SDK (from user 'teamcity'):

echo y | android update sdk --filter platform-tools --no-ui
echo y | android update sdk --filter tools --no-ui
echo y | android update sdk --filter build-tools-20.0.0 --no-ui --all
echo y | android update sdk --filter android-19 --no-ui
echo y | android update sdk --filter extra-android-m2repository --no-ui
echo y | android update sdk --filter extra-google-m2repository --no-ui
echo y | android update sdk --filter sys-img-armeabi-v7a-android-19 --no-ui --all
echo y | android update sdk --filter sys-img-x86-android-19 --no-ui --all

##Gradle

cd /opt
wget https://services.gradle.org/distributions/gradle-2.2.1-bin.zip
unzip gradle-2.2.1-bin.zip

Create /etc/profile.d/gradle.sh

export GRADLE_HOME=/opt/gradle-2.1
PATH=$PATH:$GRADLE_HOME/bin

##Android emulator

android create avd --force --name test --target android-19 --abi armeabi-v7a

Create /opt/start-emulator.sh

#!/bin/bash

emulator -avd test -no-skin -no-audio -no-window &
adb wait-for-device
adb shell input keyevent 82
chmod +x start-emulator.sh

Add the following to /etc/rc.local

su - teamcity -c "/opt/start-emulator.sh &"

##Links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment