Estimated reading time:
Two products that I love and have become an essential part of my Sitecore life are Unicorn and Octopus Deploy - I plan on writing about my adventures with setting up CI/CD using Octopus Deploy soon, but for now here is a useful Step Template for calling the Unicorn sync methods remotely during your deployment in Octopus.
For the purposes of this post, I’ll assume that you are familiar with both Octopus and Unicorn.
To install the step template, copy the json string at the bottom of the post and import into the Step Template library:
This will give you a new template you can use in your projects. Add the step to your project and you will get the following options:
Fill in the following fields:
- Shared Secret : This is the shared secret key that is held in the
Unicorn.UI.configfile. See this page for instructions on setting up the automated tool security: https://github.com/kamsar/Unicorn#use-the-automated-tool-api
- Site Url : Set this to the url of the site that the Octopus Tentacle can use to call the unicorn api. You can type the url here or use an Octopus Variable
- MicroCHAP DLL Location : You need to make sure that the MicroCHAP.dll file is included in your project and that the Tentacle canread that file. This is for the newer style authentication that Unicorn uses
- Configurations : This is a list of all the configurations that you want to sync. You can add as many as you want here, separate each configuration with a new line
And thats it. Add that to your deployment process and it will automate the Unicorn sync.
###Whats in the step template?
For those that are interested in the PowerShell script, here it is:
First we set the
$ErrorActionPreference, this tells Octopus what the default action to take on an error is. This can be overridden in the process step when you add it to a project.
Next we add the
MicroCHAP.dll so that it can be used by the rest of the script. The
Get-Challenge functions are from the
Unicorn.psm1 file in the repo https://github.com/kamsar/Unicorn/tree/master/doc/PowerShell%20Remote%20Scripting.
Finally we split the configurations variable on a new line and call the
Sync-Unicorn function with all the variables set in the UI. Simples :)
Here is the json object that you can use to import the Step Template into Octopus Deploy:
Here is a gist that contains the step template for importing into Octopus - OctopusDeploy-Unicorn-Step-Template.json