Continuous Integration with Gulp and Sitecore Powershell Extensions Part 2 – TeamCity Integration

This blog article is continuation of my earlier blog Continuous Integration with Gulp and Sitecore Powershell Extensions Part 1. In this blog, I will show how we can use TeamCity to build and deploy the code and Sitecore items to a Sitecore instance which resides in a different physical server than the Build Server where TeamCity runs.

QA Server Setup

I am going to deploy the code and Sitecore items in my QA environment for the Cobbler application. As I setup my local environment with Sitecore and Cobbler, I have done the same for the QA environment. I installed Sitecore 8.1 with Powershell using SIM. Then I installed the initial Cobbler package (can be found in Github). I also, created an empty website in IIS for ElfWebApi. My Cobbler website is in C:\Websites\Cobbler and ElfWebApi is in C:\Websites\Elf folder in the QA server. Since these two folders where the code will be deployed by TeamCity from a different physical build server, I had to share the folders over network. I created two shares called ‘Cobbler’ and ‘Elf’ in the QA server. If my QA server name is QAServer, the network path to those two shares are \\QAServer\Cobbler and \\QAServer\Elf. I needed to add these two paths in the gulp-config.js file as follows:


That’s all for the QA Server setup.

Script Changes

There were not much changes required in the scripts, but I needed to create a new set of scripts for the QA deployment from the original scripts, because the publish folders are changed as highlighted in the above picture. I also had to create a new script to publish Sitecore serialized items in the Cobbler data folder in the QA server. The Deserialization scripts will look into this folder to update Sitecore items. A new deserialization script was also created because the URL for the QA server is different than the local environment. Following are the new scripts:

Publish-Cobbler-QA –> Publishes code to the Cobbler website in the QA Server

Publish-Elf-QA –> Publishes code to the Elf webapi site in the QA Server

Publish-Cobbler-Design-QA –> Publishes design files to Cobbler website in the QA Server

Publish-Cobbler-Items-QA -> Publishes Serialized Sitecore Items to Cobbler data folder in the QA Server. This is the new script.

Deserialize-Cobbler-Items-QA –> Runs DeSerializeItems-qa.ps1

DeployAll-QA –> Runs multiple scripts to deploy files and Sitecore Items to the website in the QA server.

Deploy-Projects-QA –> Publishes only the deployment files. No Sitecore item gets deployed.

An additional change in the Cobbler.Web project was to add the SlowCheetah for the Sitecore.config transformation for the  QA build configuration. The SerializationFolder setting for the QA server is different than Local environment.

<setting name=”SerializationFolder” value=”$(datafolder)/serialization” />

This enables us to deploy the right Sitecore.config to the QA environment.

Build Server Setup

The build server had to setup to run the gulp script. I had to install node.js and gulp in the build server. I downloaded node.js from here. Once node is installed in the build server, I installed gulp in the server using the following command in the command window.

 npm install gulp -g -prefix=”C:\Program Files (x86)\nodejs”

Make sure to open the command prompt in administrator mode. The above command installs gulp in the same directory as where node is installed. As node path is set to environment variable PATH, gulp is also available from any location in the server.

Since the Powershell remote scripts will run from the build sever, I installed SPE Remoting package in the build server. I copied the SPE files in the following folder as build.server is the account that is used to run the TeamCity Build Agent.


Build Configuration

In TeamCity I created following build steps


The third build step is the one to run the gulp scripts. This is a custom command line script that TeamCity runs using command prompt. The script first runs npm install. That installs the dependencies in the local node_modules folder. Next, it calls gulp to run my DeployAll-QA. This calls all other gulp script that deploys code and Sitecore items.


Final Words

With power of Sitecore Powershell Remoting and Gulp I successfully created a Continuous Integration using TeamCity for my QA environment. Developers adding new or modifying Sitecore items can serialize the items by running the Serialize-Cobbler-Items-Local gulp script in their environment and check in the items in the source control. TeamCity build will check out the Sitecore items from the source control and deserialize the items in the QA server or any remote server the build is configured for.




About Himadri Chakrabarti

I am a software developer architect and a Sitecore MVP. My professional interest is everything and anything related to Software Architecture, .NET, Sitecore, Node.js, NoSQL etc. Outside of my profession, I am a hobbyist photographer. Link to my photography site
This entry was posted in CI, Gulp, Powershell, Sitecore and tagged , , , . Bookmark the permalink.

3 Responses to Continuous Integration with Gulp and Sitecore Powershell Extensions Part 2 – TeamCity Integration

  1. michaellwest says:

    Excellent! Thank you for sharing. For those interested in seeing more about the SPE Remoting module check out this page in the documentation where I also link a video to get it setup:

  2. Pingback: TeamCity Digest #4 | TeamCity Blog

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s