Automating Optimizely DXP Deployments with GitLab CI/CD

Posted on Sunday, February 23, 2025

Introduction

This blog post will explore the GitLab CI/CD pipeline configuration for deploying to Optimizely DXP. I wanted to be able to automate as much as possible every deployment steps to DXP, including the build stages, so that almost none of the operations were manual. The end result looks as followed: GitLab CI/CD DXP Template repository

I must say, this is clearly easier that I initially thought. In general, a full run, starting from the build to the latest stage where it deploys to production can take approximatively 30 minutes. 

PowerShell and GitLab CI

GitLab uses bash as its default shell when you configure a runner. In my own setup, I have decided to use the docker image and configure two different runners in the same docker instance (yes you can do this). One for running bash based scripts and the other that needs to run PowerShell based scripts. Consequently, the pipeline heavily utilizes PowerShell (pwsh tag) for deployment tasks as they are used in my configuration to stipulate to use my PowerShell based runner instead of the default one. Optimizely DXP's APIs and deployment commands are PowerShell-based, making it a prerequisite for certain stages. You'll find PowerShell scripts handling package uploads and triggering deployments.

Here's an example where the tag pwsh has been specified: 

send-package-dxp:
  stage: send-package
  image: mcr.microsoft.com/powershell:lts
  tags:
    - pwsh
  script:
    - Install-Module -Name EpiCloud -Force
    - Connect-EpiCloud -ClientKey $DXP_CLIENT_KEY -ClientSecret $DXP_CLIENT_SECRET -ProjectId $DXP_PROJECT_ID
    - $packageLocation = Get-EpiDeploymentPackageLocation
    - $foundPackageLocations = Get-ChildItem -Path $ARTIFACTS_LOCATION -Filter "*.nupkg" | Sort-Object -Property Name -Descending
    - $resolvedPackagePath = $foundPackageLocations | Select-Object -First 1
    - "Write-Host \"The following package will be deployed: $resolvedPackagePath\""
    - Add-EpiDeploymentPackage -SasUrl $packageLocation -Path $resolvedPackagePath.FullName

Without the pwsh tag, these PowerShell commands would fail to execute properly in GitLab CI/CD, as the default shell does not support them.

Pipeline highlights

  • Handling Failed Deployments: The pipeline includes rollback mechanisms to reset or complete failed deployments.

  • Manual Triggers for Preproduction and Production: To add a safety net, the preproduction and production deployment stages are set to manual, allowing for final verification before releasing.

Here's a visual example: 

example 1

And of the job dependencies:

example 2

Final Thoughts

As a reminder, you can refer to the complete files available in the repository: GitLab CI/CD DXP Template.

By using a well-defined CI/CD pipeline for Optimizely DXP, you can: 

  • Reduce manual deployment work.
  • Ensure consistency across environments.
  • Minimize deployment risks.
  • Enable easy rollbacks if needed.

This GitLab CI template brings structure to your DXP deployments and makes life easier for your development and operations teams.

Happy deploying! 🚀