Automating Sitecore Builds using Jenkins

Bhavik Patel • 12/23/2014

It is often an expensive task to manually publish both code and content for a Sitecore site manually to an integration environment. Usually, a person is assigned to be a “build master”, responsible for checking out and compiling code, making sure that everything works as expected, and also manually publishing the master database to the web database. It becomes even more difficult if the build master is not available, because he or she may be the only person who has the knowledge (and permissions) to deploy code to the integration server.

Jenkins (http://jenkins-ci.org/) is a tool that executes jobs for you repeatedly, and it can reduce, even eliminate, manual processes for publishing a Sitecore site to an integration server. Consider the following tasks that can be performed by Jenkins:

  • Poll source control for new code check-ins (or be notified by your source control when changes are checked-in).
  • Perform a build and publish of your Sitecore .NET solution, and copy that published code to the hosted Sitecore website.
  • Publish the Sitecore Master database (to the Web database).

It’s fairly simple to set things up. First, you’ll have to install Jenkins on the integration server. If you use the Windows installer that is available for download, it will take care of setting up a Windows service that will run Jenkins, manage tasks, and run those tasks when required. More information about installing Jenkins can be found on their website. After that, you can setup a new project in Jenkins and configure your project as follows:

  • Add your source code management (SCM) software for the project. A variety of plugins for Jenkins are available to support different SCM software.
  • Set up polling for your SCM to check for code check-ins, or have your SCM notify Jenkins using post-commit hooks when code is checked-in.
  • Set up Build tasks that will execute when Jenkins detects that code changes have been made, as follows.
    • Compile and publish the .NET code using MSBuild.exe. For example:
      "C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe" YourSolution.sln /p:DeployOnBuild=true /p:PublishProfile=PublishFileSystem
    • Copy the published code to the Sitecore website that is hosted on the server. You can use robocopy or xcopy from the command line to accomplish this. For example:
      xcopy C:\Temp\YourSolution C:\Web\YourSitecoreWebsite /s /e /y
    • Publish the Sitecore website (Master to Web database). We chose to create a custom ASP.NET page in the Sitecore solution that uses the Sitecore API to publish the website. In order to invoke this page, we also had to install a plugin for Jenkins called the HTTP Request Plugin.

And that’s it. Everytime code is checked-in, Jenkins detects the changes, checks everything out, builds and publishes the compiled code, and publishes the Sitecore Master database to the Web database. Finally, I wanted to mention that everything mentioned above doesn’t just apply to Sitecore websites. Jenkins can help with any type of automated build scenarios you have for your particular projects.

Bhavik Patel

Bhavik is a .NET developer with over 9 years of experience, focusing on Sitecore CMS for the last 3 years. He has worked on several Sitecore CMS projects in both single-site and multi-site scenarios, and truly enjoys how extensible it is. He has a passion for problem solving and using technology to create engaging websites and applications. Bhavik is a Sitecore Technology MVP, 2015 and 2016.

Explore topics:

Other Blog Posts from Bhavik Patel



Subscribe for insights, trends and big ideas