Why Aren't My Sitecore Roles Syncing Via Unicorn?
Unicorn is a fundamental tool in every Sitecore developer's toolbox, allowing database content to sync across different environments. While Unicorn is primarily used to sync dev content, settings, and configuration items in Sitecore, it can also sync users and roles.
I recently had an issue where user roles were not syncing between environments. Troubleshooting the problem was tricky because - as it turns out - the Unicorn user interface hides some critical information about the configuration of the Unicorn data store.
User roles were not syncing in higher environments - during a Unicorn sync, the Foundation.Serialization.Roles configuration reported 0 synced items. The YML files were present on disk and the
roleDataStore setting looked to be configured properly. Just to be safe, I double-checked the Physical root path in the Unicorn control panel:
And of course, the corresponding value in the Unicorn Roles configuration:
<roleDataStore type="Unicorn.Roles.Data.FilesystemRoleDataStore, Unicorn.Roles" physicalRootPath="D:\Client\Source\$(layer).$(module)\$(configurationName)" singleInstance="true"/>
physicalRootPath path above resolves to:
roleDataStore path defined in configuration definitely matches what the Unicorn control panel is showing, right? Actually, no - look closer.
I spent a lot of time debugging various issues with file paths and folder access. As it turns out, the configured
physicalRootPath for the
roleDataStore was simply wrong - a
. was placed where a
\ should have been (subtle!).
So what threw me off? The Physical root path displayed for the Foundation.Serialization.Roles configuration in the Unicorn control panel was not showing me the path configured for the
roleDataStore. It was displaying the default
targetDataStore that was set up for the other (content) configurations. This was kind of a red herring.
About Unicorn Data Stores
Unicorn has a few different types of commonly used data stores. Each serves the purpose of telling Unicorn where to find serialized YML items on disk, but differ in the types of content being synced. I've also linked the relevant Unicorn source code and examples that demonstrate each data store:
targetDataStore- the vast majority of Unicorn serialization is content items in Sitecore, defined by this value; GitHub: Unicorn.config
roleDataStore- user roles are synced via this store; GitHub: Unicorn.Roles.config
userDataStore- individual users are synced via this store; GitHub: Unicorn.Users.config
In short, Unicorn's control panel doesn't display the
roleDataStore for a configuration's Physical root path, but instead displays the default
targetDataStore. If you're debugging sync issues with roles, remember to reference your configuration files directly to verify paths!
Do you have questions, comments, or corrections for this post? Find me on Twitter: @BrandonMBruno