Sitecore Unicorn Sync

Octopus.Script exported 2016-07-14 by GuitarRich belongs to ‘Sitecore’ category.

Syncs all the specified configurations via the Unicorn remote sync PowerShell script. Uses the newer MicroChap security layer. Please see the following post for instructions: http://www.sitecorenutsbolts.net/2016/03/14/Octopus-Deploy-Step-for-Unicorn-Sync/

Parameters

When steps based on the template are included in a project’s deployment process, the parameters below can be set.

Shared Secret

SharedSecret

The shared secret used for the MicroChap handshake

Site Url

SiteUrl

The Url of your content authoring system. Must be able to view /unicorn.aspx

MicroCHAP DLL Location

MicroChap

The location of the MicroCHAP.dll file in your project

Configurations

Configurations

Add a configuration per line

Script body

Steps based on this template will execute the following PowerShell script.

$ErrorActionPreference = 'Stop'

Add-Type -Path "${MicroChap}\MicroCHAP.dll"

Function Sync-Unicorn {
	Param(
		[Parameter(Mandatory=$True)]
		[string]$ControlPanelUrl,

		[Parameter(Mandatory=$True)]
		[string]$SharedSecret,

		[Parameter(Mandatory=$True)]
		[string[]]$Configurations,

		[string]$Verb = 'Sync'
	)

	# PARSE THE URL TO REQUEST
	$parsedConfigurations = ($Configurations) -join "^"

	$url = "{0}?verb={1}&configuration={2}" -f $ControlPanelUrl, $Verb, $parsedConfigurations

	Write-Host "Sync-Unicorn: Preparing authorization for $url"

	# GET AN AUTH CHALLENGE
	$challenge = Get-Challenge -ControlPanelUrl $ControlPanelUrl

	Write-Host "Sync-Unicorn: Received challenge: $challenge"

	# CREATE A SIGNATURE WITH THE SHARED SECRET AND CHALLENGE
	$signatureService = New-Object MicroCHAP.SignatureService -ArgumentList $SharedSecret

	$signature = $signatureService.CreateSignature($challenge, $url, $null)

	Write-Host "Sync-Unicorn: Created signature $signature, executing $Verb..."

	# USING THE SIGNATURE, EXECUTE UNICORN
	$result = Invoke-WebRequest -Uri $url -Headers @{ "X-MC-MAC" = $signature; "X-MC-Nonce" = $challenge } -TimeoutSec 10800 -UseBasicParsing

	$result.Content
}

Function Get-Challenge {
	Param(
		[Parameter(Mandatory=$True)]
		[string]$ControlPanelUrl
	)

	$url = "$($ControlPanelUrl)?verb=Challenge"

	$result = Invoke-WebRequest -Uri $url -TimeoutSec 360 -UseBasicParsing

	$result.Content
}

$configs = $Configurations.split("`n")
Sync-Unicorn -ControlPanelUrl "$($SiteUrl)/unicorn.aspx" -SharedSecret $SharedSecret -Configurations $configs

Provided under the Apache License version 2.0.

Report an issue

To use this template in Octopus Deploy, copy the JSON below and paste it into the Library → Step templates → Import dialog.

{
  "Id": "d5adc467-69a8-49ca-b4d0-4f793fad4d62",
  "Name": "Sitecore Unicorn Sync",
  "Description": "Syncs all the specified configurations via the Unicorn remote sync PowerShell script. Uses the newer MicroChap security layer. Please see the following post for instructions: http://www.sitecorenutsbolts.net/2016/03/14/Octopus-Deploy-Step-for-Unicorn-Sync/",
  "Version": 14,
  "ExportedAt": "2016-07-14T15:40:31.349+00:00",
  "ActionType": "Octopus.Script",
  "Author": "GuitarRich",
  "Parameters": [
    {
      "Name": "SharedSecret",
      "Label": "Shared Secret",
      "HelpText": "The shared secret used for the MicroChap handshake",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "Sensitive"
      }
    },
    {
      "Name": "SiteUrl",
      "Label": "Site Url",
      "HelpText": "The Url of your content authoring system. Must be able to view `/unicorn.aspx`",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "MicroChap",
      "Label": "MicroCHAP DLL Location",
      "HelpText": "The location of the MicroCHAP.dll file in your project",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "Configurations",
      "Label": "Configurations",
      "HelpText": "Add a configuration per line",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "MultiLineText"
      }
    }
  ],
  "Properties": {
    "Octopus.Action.Script.Syntax": "PowerShell",
    "Octopus.Action.Script.ScriptBody": "$ErrorActionPreference = 'Stop'\n\nAdd-Type -Path \"${MicroChap}\\MicroCHAP.dll\"\n\nFunction Sync-Unicorn {\n\tParam(\n\t\t[Parameter(Mandatory=$True)]\n\t\t[string]$ControlPanelUrl,\n\n\t\t[Parameter(Mandatory=$True)]\n\t\t[string]$SharedSecret,\n\n\t\t[Parameter(Mandatory=$True)]\n\t\t[string[]]$Configurations,\n\n\t\t[string]$Verb = 'Sync'\n\t)\n\n\t# PARSE THE URL TO REQUEST\n\t$parsedConfigurations = ($Configurations) -join \"^\"\n\n\t$url = \"{0}?verb={1}&configuration={2}\" -f $ControlPanelUrl, $Verb, $parsedConfigurations\n\n\tWrite-Host \"Sync-Unicorn: Preparing authorization for $url\"\n\n\t# GET AN AUTH CHALLENGE\n\t$challenge = Get-Challenge -ControlPanelUrl $ControlPanelUrl\n\n\tWrite-Host \"Sync-Unicorn: Received challenge: $challenge\"\n\n\t# CREATE A SIGNATURE WITH THE SHARED SECRET AND CHALLENGE\n\t$signatureService = New-Object MicroCHAP.SignatureService -ArgumentList $SharedSecret\n\n\t$signature = $signatureService.CreateSignature($challenge, $url, $null)\n\n\tWrite-Host \"Sync-Unicorn: Created signature $signature, executing $Verb...\"\n\n\t# USING THE SIGNATURE, EXECUTE UNICORN\n\t$result = Invoke-WebRequest -Uri $url -Headers @{ \"X-MC-MAC\" = $signature; \"X-MC-Nonce\" = $challenge } -TimeoutSec 10800 -UseBasicParsing\n\n\t$result.Content\n}\n\nFunction Get-Challenge {\n\tParam(\n\t\t[Parameter(Mandatory=$True)]\n\t\t[string]$ControlPanelUrl\n\t)\n\n\t$url = \"$($ControlPanelUrl)?verb=Challenge\"\n\n\t$result = Invoke-WebRequest -Uri $url -TimeoutSec 360 -UseBasicParsing\n\n\t$result.Content\n}\n\n$configs = $Configurations.split(\"`n\")\nSync-Unicorn -ControlPanelUrl \"$($SiteUrl)/unicorn.aspx\" -SharedSecret $SharedSecret -Configurations $configs\n",
    "Octopus.Action.Script.ScriptSource": "Inline"
  },
  "Category": "Sitecore",
  "HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/sitecore-unicorn-sync.json",
  "Website": "/step-templates/d5adc467-69a8-49ca-b4d0-4f793fad4d62",
  "Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADNQTFRF////5DAm5j00+MvJ/fLx62Rc7n548ZeS+tjW/OXk6VdP9bGt50pB7HFq97678IuF86SgPP2jTgAAB6BJREFUeNrsXdmuqzAMLNk3CP//tQfaAl3ikFKbclDm4epKRypMYju2kwyXS0VFRUVFRUVFRUVFRUVFRUVFRcUJIXintZIzlNYdF/+LA++VbABI1fP/QUKDHB7Y6GOTEb5lTSFY649qZ75tPkTrj8fCKtZsAFP2UDQ62WyG7I5jU6H5CsGfgsZBqHDXoMD9Nh7btkFD+0O316xBBNM/omFcgwxnfjIdDQH2nxQrGxLInT2Fs4YIjP97s9rfvIRqSKF2SouFa4jhdmFiyXkMTHZweVPu5kHGoUzn5lrAc97rtngMmDkKj6GYTdqH8SocgUkRD6byJYbp3a+ZlPBQJYWS1eGXTMTq04MuDjh8LTcI4mdx98P6yKofReEWvcxbqWdaGh5xJbPYNH75CjOS1OZEWWufCyB+54DFeqKKAD90ZR3924xC7+jwOQdRlOUNspt0xHacyURRG5GCUVd0AgzEDNO41A7eqOgsdzHhXaIKyASvig/7REeISSBvNWBHeUXbjgA9HX+1akn9Pe6XP0DLLspiYvfsP1lg9i2h4UqaFiZZCLZ7rFPrkcWSeQhFi1aM0cPReAkUsihKHh6agYmhMYB+t8bANdsa3zdtXP2XPx92SEkfC8UWemYgCSLoEWvZxuugh3KK2Iu8pIv47AwSPQIL8sT6WrWFlx4QR3d3T7fOwr0HDkzJNxlRSz8h73v1DpiSFt2yENfCZH/OA1Oy3bY64pAlIlRIedyYr2izd8/g+iCgmnQgzRbhVllI/3HzmmhpXT3TvOTpjMuiBl+87ATulrVpa/CYLsLoq6hrgIqI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