Continuous Integration – Build automation for Sitecore 9 solution with Azure DevOps

Tags: Sitecore 9, CI, Continuous Integration, Automation, Azure, Azure DevOps, DevOps

It is assumed that you already have the repository in somewhere that you store your Sitecore 9 solution. Your Sitecore solution contains the web projects as well as TDS projects to maintain Sitecore items. You would like Azure DevOps to handle the solution build for you by compiling the source codes and generate Sitecore update packages. Then continue to read this article.

You can configure a build for the solution under the Pipelines -> Build menu by clicking on New -> New Build Pipeline link:

Azure DevOps allows you the ability to pull the source codes from either Azure Repos Git/Git Hub/Git Lab Enterprise/Subversion/Bitbucket Cloud/External Git. For me, the natural choice is to keep my source codes in Azure Repos Git so I can easily manage both source codes and builds in one place:

Once you have configured the source control, the next step is to choose a predefined template for your build. A template will contain a number of tasks that will be executed during the build:

For me, I know exactly which tasks that I need to employ for the build, so I choose the "Empty job" option in the link instead.

Before setting up the tasks for the build, you should set up some variables that are going to be used by the tasks to avoid repetition. The following variables are what I need:

 

BuildConfiguration – Web Build

  • Taken from Visual Studio build configuration setting of the solution/project. I want to use the Web Build configuration. This configuration applies specifically to my web projects

BuildPlatform – any cpu

  • Taken from Visual Studio build configuration setting of the solution/project. The platform target of my solution is "Any CPU"

BuildTDSConfiguration – TDS Build

  • Taken from Visual Studio build configuration setting of the solution/project. I want to use the TDS Build configuration. This configuration applies specifically to my TDS projects

TDS_Key – your TDS license key

  • This will be required when generating Sitecore package

TDS_Owner – TDS license owner

  • This will be required when generating Sitecore package

 

Next step is to select an agent that will be responsible for executing the tasks:

Think about the build server as your development box. Whatever you need in your development environment to build a solution, you will need them in the build server as well. The tasks will need to accomplish that.

What need to be done is add the following tasks to the agent’s job.

  1. Nuget Tool Installer

If your solution uses Nuget to manage the third-party dll libraries, you will need this task (as well as the next task). If not, skip this task and the next task and begin with task 3.

This task makes sure Azure DevOps can obtain a version of Nuget from the internet to be used:

  1. Nuget

It is obvious that the next step is to restore the nuget package for the solution. Thus, add the Nuget task:

In the "Feeds to use" option, I would choose the "Feeds in my Nuget.config" option, then select the path to my Nuget.config file:

  1. Visual Studio Build

After the third-party dll libraries can be restored via Nuget, the solution can be built. Add the "Visual Studio Build" task. This task uses MSBuild behind the scene:

The following MSBuild Arguments are important:

/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"

In layman terms, it can be explained briefly as: I want to generate a package from the build, this package will be used later to deploy to an environment.

This is important if you want to apply Continuous Delivery (CD) process after CI process (which will be another topic)

Set the platform with the BuildPlatform variable that was defined earlier:

Set the configuration with the BuildConfiguration variable that was defined earlier:

Your solution/projects must be configured with "Build" in Visual Studio for the selected build configuration. Otherwise the package will not be generated. The generated package will be in .zip format.

  1. Add another Visual Studio Build task. This time, configure it to build TDS projects and generate Sitecore packages. The different is in configuration:

Your TDS projects must be configured with "Build" in Visual Studio for the selected build configuration. Otherwise the Sitecore packages will not be generated. The generated packages will be in .update format

  1. Copy Files

Sitecore package update file will not be copied automatically to the build location so you will need to have a task to do it manually.

You will need to specify the source folder where the .update file is generated in step 4. It should be located in the bin folder of the project. Hence the path would be something like: SolutionFolder/TDSProjectFolder/bin

You will then need to specify the target folder to copy the file to. By default, it should be $(Build.ArtifactStagingDirectory) unless you want to change it. This value should match the value in MSBuild Arguments that you input in step 3.

If you have multiple TDS projects in your solution, repeat this step and change the source folder in each additional task

  1. Publish Build Artifacts

This final task will produce a final package which contains all generated packages to a single location. This final package can be used later for CD process.

You won’t need to change anything here unless you want to change the default values.

 

After adding all the tasks above, you can save and queue a build for the solution. The build is success when all go green:

You can then find the generated package at the Artifacts link at the top right corner. I have the artifact named "drop" here:

If your package contain both website solution in a .zip file and Sitecore .update packages for TDS projects then congratulation! You have successfully configured the CI process on Azure DevOps.

But hang on a second. 

You do not want to manually build the solution. You want the build to be triggered as soon as someone commit the source codes to a certain branch. 

Then do not miss the final step here. 

Go to the Triggers menu and check the "Enable continuous integration" checkbox, then specify the branch to build the codes from:

 

In the next article, I will detail the steps needed for CD process to Azure hosted sites.

Stay tuned.

5 Comments

  • Hardy said

    Thank you, this is exactly what I need. Can't find any other document about this. Waiting for your new articles.
    Many many thanks

  • mobile legends said

    Quality posts is the important to invite the people to pay a
    visit the website, that's what this site is providing.

  • xxx said

    What's up, this weekend is nice in support of me, because this point in time i am reading this fantastic informative post here at my home.

Add a Comment