Using Sitecore Serialization with Azure DevOps
Sitecore Serialization is a powerful capability to leverage with your DevOps pipelines. There are a ton of options beyond publishing via serialization, but for the sake of this article we will walk through one method of automating serialization via Azure DevOps and Sitecore Serialization. This has the following assumptions:
- Azure DevOps with Dedicated Agents in an Agent Pool (not the Azure Hosted Agents)
- Package Based Deployment
- Use of Azure DevOps Pipeline Variables
- Creation of an Azure DevOps Pipeline where it deploys in the following order per environment:
- Content Managment Deployment Step
- Content Delivery Deployment Step (Can be ran in parallel with the Content Management deploy step)
- Sitecore Serialization Step
Our step for Sitecore Serialization (using Staging as an example), looks like the following:
The steps to set this up are as follows.
Contents
Ensure Non-Interactive Login is Enabled in Your Environment
A non-interactive login is required to execute a dotnet sitecore login. To that end, follow this Sitecore guide and keep track of the client credentials, client id, and client secret as these will be used as Azure DevOps variables to create a successful login: Configure a non-interactive client login | Sitecore Documentation
Create Sitecore Serialization Step in Azure DevOps
In this step, you will want to create Azure DevOps variables as these will be utilized when connecting to the Identity Service and Content Management instances to execute serialization. Once those are created, the three key components run on the agent in the Serialization Step are as follows:
- .NET Core installation on the agent (required for Sitecore Serialization)
- Extract files from the package used for containing our serialization item package
- A command line step to run our serialization script
From this point, we can create our script.
Sitecore Serialization Script
The actual script used in this example has several steps and includes some error handling.
dotnet tool restore
dotnet sitecore login --authority https://$(SI-CLI-HostName) --cm https://$(CM-HostName) --allow-write true --client-credentials true --client-id SitecoreCliPipeline --client-secret $(SI-CLI-ClientSecret)
dotnet sitecore ser pkg install -f $(System.ArtifactsDirectory)\_Platform\Items\Sitecore.itempackage
IF %ERRORLEVEL% NEQ 0 (
EXIT /B %ERRORLEVEL%
)
dotnet sitecore publish
IF %ERRORLEVEL% NEQ 0 (
EXIT /B %ERRORLEVEL%
)
EXIT /B 0
Dotnet Tool Restore
The first execution in the script is to ensure that we have the Sitecore Serialization toolset available. To that end we use the dotnet tool restore
command.
Dotnet Sitecore Login
With the underlying .NET core toolset in place, we can now authenticate into our Identity Service and Content Management instance. Per the full script above, this looks like the following where items like $(SI-CLI-HostName)
are variables called from the centrally stored Azure DevOps Variables.
dotnet sitecore login --authority https://$(SI-CLI-HostName) --cm https://$(CM-HostName) --allow-write true --client-credentials true --client-id SitecoreCliPipeline --client-secret $(SI-CLI-ClientSecret)
Dotnet Sitecore Ser Pkg Install
In this step, we want to use a Sitecore Content Serialization Package. We had already created this as part of our development, and it’s made available to use via the second component in our Sitecore Serialization Step (a zip file we extract). This extracted zip contains our .itempackage containing serialization information. We install and execute this via the following:
dotnet sitecore ser pkg install -f $(System.ArtifactsDirectory)\_Platform\Items\Sitecore.itempackage
IF %ERRORLEVEL% NEQ 0 (
EXIT /B %ERRORLEVEL%
)
Dotnet Sitecore Publish
A final optional step is to publish our serialized content to the Web database. I state optional, as in some cases, such as a Production environment with Content Authors, you may want to tightly control which items are published versus forcing a publish of all items in case there is a lack of governance/workflows as that could publish content not ready for Production (You should seriously leverage workflow and governance to prevent items from being publishable until they have completed their respective workflows).
In the example provided, the publish is executed as a publish all but there are a ton of options, inclusive of targeting which items to publish: The CLI publish command | Sitecore Documentation
Note that by not setting a target when executing dotnet sitecore publish
, it will publish to the default publishing target (usually Web), but you can target other publishing targets in the case of having multiple.
Conclusion
The above steps and example are one way of serializing Sitecore content in an automated fashion. I recommend you evaluate all the wonderful serialization options available, alongside the power of Azure DevOps, to find which one is right for your needs.