build · deployment

Sitecore 9 – Automated deployment with TeamCity and automated code review with SonarQube

This post is a summary of my workshop at the company. However, it might be an initiative of your own approach for automated Sitecore XP 9.3 Initial Release deployment with TeamCity and automated code review with SonarQube

  • Applying build and integration of Sitecore Helix
  • Using XML Transforms to support multiple build configurations
  • Using Unicorn – a Sitecore utility designed to simplify deployment of Sitecore items across environments automatically
  • Dedicating to my simple development framework version 2.5
  • Using TeamCity: powerful Continuous Integration out of the box
  • Using SonarQube: an open-source tool that is used as a continuous inspection of code quality and to perform static code analysis to detect bugscode smellsvulnerabilities, it can report duplicated codecoding standardsunit tests, code coveragecode complexitycomments

Setup Prerequisites

How to set up the automated deployment

  1. setup a new Sitecore XP 9.3 Initial Release instance whose host name should be viethoang.local
    • bind the second host name hoavi.local
    • bind the third host name demo.local
  2. install TeamCity 2019.2
  3. import TeamCity_VietHoangSitecore.zip to TeamCity (note: for your information)
    • Administration -> Projects Import -> Upload Archive then click  Configure Import Scope button
    • auto_1
    • check VietHoangSitecore checkbox and then click Start Import button
    • auto_2
  4. go to Administration -> -> VietHoangSitecore -> Release -> Edit Configuration
    • auto_5
  5. click on Parameters and then correct 03 Configuration Parameters below as they might be different between my machine and your machine
    • auto_3
    • vhs.instanceUrl: your Sitecore instance URL
    • vhs.sitecoreDataFolder: the full path of data folder of your Sitecore instance
    • vhs.websiteRoot: the full path of website folder of your Sitecore instance
  6. run build Release
    • auto_4
    • hopefully you will have no any issues and when the build is done, you would see something like this:
    • This slideshow requires JavaScript.

  7. verify the automated Sitecore deployment on your machine:
    • open a browser, navigate to http://hoavi.local
    • open a browser, navigate to http://demo.local
    • hopefully, you would see something like this:
    • This slideshow requires JavaScript.

How to set up the automated code review

Inspired by this article Ensure and monitor your source code quality with SonarQube and Analyze your Sitecore source code of Arvind Gehlot

  1. download SonarQube 8.1 Community edition
  2. extract .zip file (Ex: C:\sonarqube) and learn about the prerequisites
  3. highly recommend doing following things so we can play around with command-line much easier
    • install chocolatey
    • open Windows PowerShell (run as administrator) and then execute Set-ExecutionPolicy -Scope CurrentUser Unrestricted
    • auto_10
  4. install OpenJdk version 11 or later: open Windows PowerShell (run as administrator) and then execute choco install openjdk
    • auto_11
  5. run SonarQube as a windows service by running as administrator C:\sonarqube\bin\windows-x86-64\InstallNTService.bat
    • auto_12
    • you may cannot start SonarQube windows service and see the error message SonarQube requires Java 11 to run in C:\sonarqube\logs\sonar.log
    • This slideshow requires JavaScript.

    • my suggestion is to edit C:\sonarqube\conf\wrapper.conf by specifying absolute path of java folder like this
    • auto_15
  6. open a browser, navigate to http://localhost:9000 and then log into by using default account admin (its password is admin)
    • auto_16
  7. to analyze the solution, we need to create a new project in SonarQube first
    • auto_17
  8. generate an unique token that identifies the project
    • auto_18
    • note the token and then click Continue button
    • auto_19
  9. select the language, it should be C#. Also, click Download button to download the scanner for MSBuild and then add the executable’s directory to the %PATH% environment variable (Ex: C:\sonar-scanner-msbuild-4.7.1.2311-net46)
    • auto_20
    • extract .zip file
    • auto_21
  10. add bin folder of MSBuild to PATH environment variable
  11. install NodeJs by executing choco install nodejs via Windows PowerShell (run as admin)
  12. finally, we should see something like the following ones in %PATH% environment variable
    • auto_22
    • Note: you may need to restart TeamCity’s Build Agent windows service after editing %PATH% environment variable as well
  13. start analyzing the code
    • normally, we start analyzing the code by running 03 following command executions one by one via command prompt
    • auto_23
    • fortunately, we have the automated deployment in place so just enable Execute the Sonar Scanner for MSBuild build step in TeamCity
    • This slideshow requires JavaScript.

    • configure SonarQube’s project name and token in TeamCity

    • auto_26
    • ensure running the build successfully via TeamCity and then log into SonarQube UI  to view the generated report, we would see something like this
    • auto_27

Got issues?

Please send your issues (with screenshots if possible) to viet.hoang.sitecore@gmail.com so that I have a chance to understand your problem and be able to suggest the solution.

Happy Sitecore Playing!

Advertisement

2 thoughts on “Sitecore 9 – Automated deployment with TeamCity and automated code review with SonarQube

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

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

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.