Sitecore CLI - 2 quirks with serialization and the what-if option

· 1 min read
Photo by Amsterdam City Archives / Unsplash

I was doing some serialization work with the Sitecore CLI and wanted to check what a pull would actually do before letting it touch anything. That is exactly what the what-if option is for:

dotnet sitecore ser pull -w

It tells you which changes would be made, without making them. Perfect for a dry run.

Well, almost. I ran into two small things that had me scratching my head for a minute, so I'm writing them down here.


Quirk 1: what-if needs allowWrite to be true

You would think that a read-only, nothing-will-be-changed command doesn't need write permissions. I thought so too.

But if allowWrite is set to false for your environment in the user.json file, you get this:

dotnet sitecore ser pull -w
What if mode is active. No changes will be made.
Environment  is not configured to allow writing data. Use what-if, or set the environment to allow writes in the user.json file.

Read that last line again. It tells you to use what-if... while you are already using what-if :-)

The solution is not very elegant, but it works: temporarily set allowWrite to true in your user.json, run the command again, and you get your dry run:

[master] Discovered 0 changes after evaluating 274 total items.
[roles] Discovered 0 changes after evaluating role list.
[users] Discovered 0 changes after evaluating user list.

Then set it back to false afterwards. Don't forget that part.


Quirk 2: the empty Environment name

Have another look at the error message above:

Environment  is not configured to allow writing data.

That double space is not a typo on my side. The environment name is simply rendered as blank.

This is actually a useful hint: it means no environment was passed, so the CLI falls back to the default environment defined in your user.json. Handy to know when you have a couple of environments configured and you're not sure which one you are talking to.

If you pass the environment explicitly with the -n option:

dotnet sitecore ser pull -w -n "TST"

...the name shows up in the response like you would expect.


Two small things, but the kind that cost you five minutes if you have never seen them before. Now you have :-)

When the CLI tells you to use what-if while you are using what-if, check your allowWrite. And when the environment name is missing, you're talking to the default one.