7

We are using Unicorn as sync mechanism for items between the dev machines.Currently we are manually deploying the yml files to different environments like SIT, UAT and PROD.

Is it possible to use Unicorn for Continuous deployment between environments like SIT, UAT and PROD.

If so how can we achieve this.

3 Answers 3

10

Yes, you can do the sync with almost any kind of script. Basically you can call the /unicorn.aspx with parameters. Here you can find the whole documentation about this. This example is working with PowerShell.

  1. Generate a very long random shared secret key, preferably using a password generator. There are no limits on character count, character types, etc but it must be > 30 characters.
  2. Install the shared secret into the Unicorn.UI.config file - or a patch thereof, under the authenticationProvider/SharedSecret node. There are comments to help.
  3. To call the tool API from a script, a PowerShell module is provided. Acquire the module and its supporting files from the doc\PowerShell Remote Scripting folder of the Unicorn git repository.
  4. Review the sample.ps1 file and adapt it to your needs, including putting the shared secret into it and setting the URL as needed. Don't worry the guts of sample.ps1 are two simple lines of code :)

Here is the sample.ps1 provided by Unicorn:

$ErrorActionPreference = 'Stop'

$ScriptPath = Split-Path $MyInvocation.MyCommand.Path

# This is an example PowerShell script that will remotely execute a Unicorn sync using the new CHAP authentication system.

Import-Module $ScriptPath\Unicorn.psm1

# SYNC ALL CONFIGURATIONS
Sync-Unicorn -ControlPanelUrl 'https://localhost/unicorn.aspx' -SharedSecret 'your-sharedsecret-here'

# SYNC SPECIFIC CONFIGURATIONS
Sync-Unicorn -ControlPanelUrl 'https://localhost/unicorn.aspx' -SharedSecret 'your-sharedsecret-here' -Configurations @('Test1', 'Test2')

# SYNC ALL CONFIGURATIONS, SKIPPING ANY WITH TRANSPARENT SYNC ON
Sync-Unicorn -ControlPanelUrl 'https://localhost/unicorn.aspx' -SharedSecret 'your-sharedsecret-here' -SkipTransparentConfigs

# Note: you may pass -Verb 'Reserialize' for remote reserialize. Usually not needed though.

# Note: If you are having authorization issues, add -DebugSecurity to your cmdlet invocation; this will display the raw signatures being used to compare to the server.

Here is my demo with a concrete example, maybe it also helps you.

0
5

It is exactly possible to use the Unicorn for Continuous Delivery. I have some suggestions:

First of all, you need to put files (which are generated by Unicorn) under source control.

You need to use a config transformations for filling a correct path to the folder with the Unicorn's files.

The next very important part is that you should deny Unicorn to deploy the content and media items to PROD server. It can override the LIVE content with dummy data. The best way to achive that is also to use the config transformations. The other way to achive that is enable the Unicorn.Configs.NewItemsOnly config. You need to configure the paths to root item of content and media and then Unicorn will add new items under it and skip existing.

And the last one is it is better to disable a transparent sync for PROD environment and run it form PowerShell scripts as it mention at the previous answer or manually. It will allow to avoid any casual updates of content on LIVE.

0
3

To add to the answers above.

No Content in PRD

Make sure you make content in its own config/project. Then with transformation kill the config in QA/PRD.

No data provider in PRD

Make sure you turn off the the Unicorn data provider in QA/PRD. When the provider is on, Sitecore reads directly from the disk instead of the database. This makes it so production Sitecore will update your yml files. When the data providers are off, Unicorn and Sitecore will only be in contact when you push the sync button.

This also guarantees that Sitecore will not contact the yml files until you are completely ready for your deployment.

Your transform file would look like this.

<?xml version="1.0" encoding="utf-8" ?>
<!-- For more information on using transformations 
     see the web.config examples at http://go.microsoft.com/fwlink/?LinkId=214134. -->
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <sitecore>
    <dataProviders xdt:Transform="RemoveAll">

    </dataProviders>
    <databases xdt:Transform="RemoveAll">

    </databases>
  </sitecore>
</configuration>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.