In this tutorial, you will gain access to some useful PowerShell scripts that I've used when setting up a Ci/Cd pipeline in Octopus deploy for an Episerver CMS powered website. These scripts are all designed to automatically update config files using Powershell. If you are new to using OCtopus deploy with Episerver, I would recommend reading this post as well, 4 Points You Should Consider Before Using Octopus With Episerver. There are several key stages when setting up a build server. Enabling configuration transforms so different values are applied to the correct environments. Running unit or integration tests. Copying the correct files onto a server and configuring the webserver to run the site. A good build tool or deployment tool will usually have scripts to do most of these tasks for you. Often you will need to write a custom PowerShell script to bend the pipeline to your will and get the process to do exactly what you need it to. If you fall into this second camp then the script below will hopefully help you!
Most of the PowerShell snippets below target Octopus variable substitution on configuration files. As we use ASP.NET it is possible to add your application configuration transforms within transform files in your application. It is common to have a web.config
and a web.release.config
and let MsBuild do the substitutions. There are two downsides of this approach:
Secrets are stored in plain text in source control
If you need to update a value you need to update your code and commit it. One benefit of this approach is that IT administrators and people who may not have Visual Studio installed can work on your build process and procedure. Avoiding updating the project code should also avoid bugs and excess testing!
There is a downside to Octopus variables, you will not have immutable configuration values stored in source control is good.
Due to these reasons, it is likely that you will store some of the different environment settings as Octopus variables. Most of the snippets below will swap values, replacing the value with Octopus variable names. If you are new to pipelines and you find yourself struggling to grasp this concept think of it as two transforms. First, you manually need to add the Octopus variables into the config files. Afterwards, Octopus will then perform transforms on these variables names 👀.
Load and Save A Config File
This first snippet will be the starting point for most of the other snippets below. This snippet loads a config file with PowerShell and then save it afterwards.
Update An AppSetting
This script will find an app setting in a appSettings.config
file and enable the 'EPi.DebugView.Enabled' setting to true
. This setting will allow you to see extra debug information while running the site. This is useful in development but should not be used in production
Change The Episerver Log File Location
This script changes the location on the server where the log files will be stored with a variable called #{OctopusVariableName}
. The transform is based on the file located C:/
Change The App Data Folder Location
This script changes the location on the server where the app_data
folder is located using a variable called #{OctopusVariableName}
. It is usually recommended to locate this outside of the website root
Update All Rewrite Rules Url
This script will update the rewrites rules section with an Octopus variable called #{OctopusVariableName}
(you might want to rename this 😉). This came in useful on a project that required a reverse proxy to handle legacy resources.
Update Redis In Your ConnectionString
This script will set your Redis connection string to use an Octopus variable instead. You will need to create these variables in Octopus #{RedisConnectionString}
, #{RedisPort}
, #{RedisPassword}
and #{RedisSSLEnabled}
Change The Episerver Indexing Service URL
This script will update the baseUri
property for the Episerver indexing service, and replace it with an Octopus variable called #{OctopusVariableName
.
Update The Episerver License File To Use An Octopus Variable
This script will update the Episerver license property and replace it with an Octopus variable called #{EPiServerLicence}
.
I hope you find value in some of these scripts. Getting a Ci/Cd pipeline up and running can be a pain. Happy Coding 🤘