Automating Sitecore XM Cloud Deployment with DevOps Pipelines: A Step-by-Step Guide
- Cristina Paolillo
- Dec 3, 2024
- 4 min read

As organizations increasingly move towards cloud-based platforms like Sitecore XM Cloud, automating deployment workflows becomes crucial for streamlining the release process, reducing errors, and maintaining consistency across environments. In this article, we’ll dive into automating the deployment of Sitecore XM Cloud through DevOps pipelines, using Azure DevOps for seamless integration and continuous delivery.
The Sitecore XM Cloud Deployment Pipeline Overview
A successful deployment pipeline for Sitecore XM Cloud involves multiple stages, from the creation of the initial deployment in the development environment to the promotion of the deployment through staging and production. This ensures that new features or updates are thoroughly tested before being exposed to end users.
The pipeline we will explore follows a structured, multi-stage approach, with automated deployment and promotion steps across three environments: Development (DEV), Staging (STG), and Production (PRD).
Key Components of the Pipeline
Here’s a breakdown of the YAML configuration for the Azure DevOps pipeline, which defines the stages and deployment steps:
Trigger Configuration
trigger:
branches:
include:
- develop
- main
The pipeline starts by specifying a trigger that listens for changes on the develop and main branches. This ensures that the pipeline is executed whenever there are new commits or changes in these key branches.
Stage: Create Deployment on DEV
The first stage of the pipeline focuses on creating a deployment in the DEV environment. It starts by restoring the necessary .NET tools and logging into Sitecore Cloud using client credentials.
- stage: create_deployment_on_dev
jobs:
- deployment: create_deployment_on_dev_job
variables:
- group: 'Sitecore DEV'
pool:
vmImage: windows-latest
environment: xmcloud-dev
strategy:
runOnce:
deploy:
steps:
- checkout: self
- script: |
dotnet tool restore
displayName: dotnet tool restore
- template: ../steps/login-to-sitecore-cloud.yml
parameters:
xmcClientId: $(xmcloud-client-id)
xmcClientSecret: $(xmcloud-client-secret)
In this stage:
Dotnet tools are restored to ensure all dependencies are available.
Login to Sitecore Cloud is facilitated through the login-to-sitecore-cloud.yml template, which uses the xmcClientId and xmcClientSecret for authentication.
Once authenticated, the pipeline proceeds with the deployment creation process:
- powershell: |
try {
$deployment = dotnet sitecore cloud deployment create --environment-id $(xmcloud-environment-id) --no-watch --no-start --upload --working-dir $(Build.SourcesDirectory) --json | ConvertFrom-Json
$deploymentId = $deployment.id
Write-Host "##vso[task.setvariable variable=deploymentId]$deploymentId"
Write-Host "##vso[task.setvariable variable=deploymentId;isOutput=true]$deploymentId"
} catch {
Write-Error "Deployment creation failed: $_"
exit 1
}
This step creates a deployment in Sitecore XM Cloud and stores the deployment ID as a variable for use in subsequent stages.
After the deployment is created, the next step is to start the deployment process using the command sitecore cloud deployment start. This command triggers the actual deployment in the DEV environment. The deployment ID, which was generated when the deployment was created, is passed into the command to identify the deployment that should be started.
- powershell: |
try {
$deploymentResult = dotnet sitecore cloud deployment start --deployment-id $(deploymentId) --json | Tee-Object -FilePath $(Build.ArtifactStagingDirectory)\start-deployment-log.txt | ConvertFrom-Json
if ($deploymentResult.IsCompleted) {
Write-Host "Deployment started successfully"
exit 0
} else {
Write-Error "Deployment failed: $deploymentResult"
exit 1
}
} catch {
Write-Error "Deployment start error: $_"
exit 1
}
displayName: 'Start deployment'
Stage: Promote Deployment to STG
Once the deployment is successfully created in DEV, the next stage promotes it to the STG environment for further validation.
- stage: promote_deployment_on_stg
dependsOn: create_deployment_on_dev
jobs:
- deployment: promote_deployment_on_stg_job
variables:
- group: 'Sitecore STG'
- name: deploymentId
value: $[stageDependencies.create_deployment_on_dev.create_deployment_on_dev_job.outputs['create_deployment_on_dev_job.CreateDeployment.deploymentId']]
pool:
vmImage: windows-latest
environment: xmcloud-stg
strategy:
runOnce:
deploy:
steps:
- checkout: self
- script: |
dotnet tool restore
displayName: dotnet tool restore
- template: ../steps/login-to-sitecore-cloud.yml
parameters:
xmcClientId: $(xmcloud-client-id)
xmcClientSecret: $(xmcloud-client-secret)
- powershell: |
dotnet sitecore cloud environment promote --environment-id $(xmcloud-environment-id) --source-id $(deploymentId)
displayName: 'Promote deployment'
The pipeline first restores tools and logs in again. Then, it promotes the deployment from DEV to STG using the dotnet sitecore cloud environment promote command, ensuring the latest changes are validated in a staging environment before moving to production.

However, before the deployment proceeds in STG, an approval check is configured to ensure that the deployment does not happen automatically. This check requires manual intervention from the relevant stakeholders to approve the deployment. This step ensures that deployments in STG are always reviewed before being promoted.
Stage: Promote Deployment to PRD
The final stage promotes the deployment to the PRD environment, ensuring that only tested and approved changes are pushed to production.
- stage: promote_deployment_on_prd
dependsOn:
- create_deployment_on_dev
- promote_deployment_on_stg
jobs:
- deployment: promote_deployment_on_prd_job
variables:
- group: 'Sitecore PRD'
- name: deploymentId
value: $[stageDependencies.create_deployment_on_dev.create_deployment_on_dev_job.outputs['create_deployment_on_dev_job.CreateDeployment.deploymentId']]
pool:
vmImage: windows-latest
environment: xmcloud-prd
strategy:
runOnce:
deploy:
steps:
- checkout: self
- script: |
dotnet tool restore
displayName: dotnet tool restore
- template: ../steps/login-to-sitecore-cloud.yml
parameters:
xmcClientId: $(xmcloud-client-id)
xmcClientSecret: $(xmcloud-client-secret)
- powershell: |
dotnet sitecore cloud environment promote --environment-id $(xmcloud-environment-id) --source-id $(deploymentId)
displayName: 'Promote deployment'
Similar to the promotion to STG, the deployment to PRD also includes an approval check that ensures the deployment doesn't happen automatically. This allows stakeholders to review and approve the deployment before it goes live.
Managing Variables Across Different Environments
A key part of the deployment process is the management of variables specific to different environments (DEV, STG, PRD). In this pipeline, we use the Azure DevOps library to handle environment-specific variables like xmcloud-client-id, xmcloud-client-secret, and xmcloud-environment-id. These variables are defined in the pipeline's variable group or set as pipeline variables, ensuring that the correct credentials and configuration are used for each environment.
For instance, during the deployment to DEV, we use:
xmcClientId: $(xmcloud-client-id)
xmcClientSecret: $(xmcloud-client-secret)l
These variables are injected at runtime, ensuring that each environment gets the correct credentials and deployment settings. The same logic applies when promoting deployments to STG and PRD, ensuring consistency across all environments.
Benefits of Automating Sitecore XM Cloud Deployments
Consistency Across Environments
By using a pipeline, deployments are automatically managed consistently across all environments, ensuring that the same configuration is used in DEV, STG, and PRD.
Error Reduction
Automation minimizes human errors during deployment, ensuring a smooth and predictable deployment process. The pipeline will automatically stop if any step fails, notifying the team of any issues.
Faster Time to Market
Automating the deployment process speeds up the release cycle, allowing new features and updates to reach users faster while maintaining high standards of quality.
Improved Collaboration
By standardizing the deployment process, the pipeline improves collaboration between development, QA, and operations teams. Developers can focus on code, while operations can rely on the automated process to handle deployment.
Comments