Configure, Package and Deploy Php projects : TeamCity Part 2

In this part we create build configurations to actually make use of build files on the previous article and deploy to the cloud using ssh commands.

TeamCity is a continuous integration tool developed by JetBrains.

The free version offers up to 20 build configurations and 3 build agents sufficient for small teams.

Required Plugin and Meta Runners

  • Deployer plugin
  • Meta runners power pack for php

You have already the running teamcity server and agents. So lets start with downloading meta runners and installing them on the teamcity.

We will be using Phing tool to configure and package the application so lets install php meta runners.

  • Download Php meta runners.
  • Put them inside the {TeamCity Data Folder}/config/projects/YourProject/pluginData TeamCity Data Folder looks like /Users/yourname/.BuildServer/ in mac

After placing meta runners file, you can see them listed for a project.

Now its time to create build configuration. Name your build and put some description if you want, here we will be using artifacts as so put in artifacts path. See screenshot below

VCS settings

We use Git to pull the sources from the bitbucket. Complete guidelines on how to configure git settings for the project is out of scope fort this article.

After you have successfully attached the VSC to the build, now its time to start adding build steps.

Step 1: Phing Build

Runner Type: PHP- Phing

Phing configuration file: build.xml

Phing parameters: -Dbuild.env=production

Before moving to another build step, we have to install Deploy Runner plugin. Make sure you restart the team city server after installing new plugin.

Step 2

Runner Type: SSH Deployer

Target: your.server: directiory/on/the/server

Transport Protocol: SCP or SFTP ( choose what your prefer)

Authentication Method : Default Private Key

Artifacts path: (This is the artifact configured and packaged by the Phing tool).

Step 3

In this step we will unpack the package on the server using ssh commands.

Runner Type: SSH Eexec

Target: your.server

Authentication Method : Default Private Key

Commands :

cd /your/repo/folder/onserver/
  unzip -o