SitecoreAI - You cannot author in an environment that deploys its own items

· 5 min read
Photo by CHUTTERSNAP / Unsplash

Here is a setup that sounds completely reasonable. One repository owns the authoring side: serialized Sitecore items plus a Platform project with config patches. The editing hosts live in their own repositories. And one environment - let's call it TST - is where the team authors items and pulls them into git.

That same environment is also a deployment target. Which is where it falls apart.

deployItems in xmcloud.build.json does not just push your items. It converts them into Items as Resources (IAR) - read-only .dat files on the file system. So the environment you author in receives its own items back as read-only resources.

I spent a while trying to configure my way out of that. There is exactly one working combination, and it is not one you can commit.

The part that actually hurts

Read-only items are annoying. Silent drift is worse.

Per the documentation: items in resource files are immutable, and if you try to edit one, Sitecore copies it to the database using the same item ID and applies your change there. If an item exists in both places, the database wins - Sitecore reads it from the database. And if you delete that copy, it is only deleted from the database and Sitecore reads it back from the resource file.

Which gives you an item that is writable but not deletable, and that always comes back. Sitecore's message when you try:

Some of selected items are in resources and cannot be deleted.

Now the real problem. Because the database copy wins on load priority, once someone edits a deployed item, every subsequent deployment of that item is silently ignored. The deploy keeps reporting success. The environment quietly diverges from the repository. Nothing tells you.

The configuration matrix

Two files interact here: deployItems.modules in xmcloud.build.json, and the modules file glob in sitecore.json. I tested every combination directly against dotnet sitecore itemres create - the exact build step that fails - and captured the exit codes rather than guessing from the output.

sitecore.json glob deployItems.modules Result What happens
resolves ["MyProject.*"] exit 0 Package created. Items become IAR.
resolves omitted exit 0 Deploys every module in sitecore.json. Absence is not "none".
resolves [] build fails Pipeline emits a bare -i → argument parse error.
resolves ["__none__"] exit 1 A filter matching nothing is an error, not a no-op.
resolves a module with no items exit 1 Filter matches, but the subtree has no serialized data.
does not resolve ["MyProject.*"] exit 1 The trap. Neutralising one file without the other.
does not resolve omitted exit 0 The only no-item success. No package created.

Note what that last row costs you. Suppressing the item deploy needs both a non-resolving glob and deployItems deleted entirely. But a non-resolving glob disables serialization for the whole repository - ser pull, ser push, ser info and ser explain all resolve zero modules, for every developer.

So it can only ever be a temporary local edit that you revert immediately. Commit it and you break the repository for everyone. Commit half of it and you break the build.

The failures, with their actual error text

An empty modules array emits a bare flag

Creating items as resources
Required argument missing for option: -i
create
  Creates a new resource item package
Usage:
  sitecore.cli [options] itemres create

With "modules": [] the pipeline still runs itemres create and still passes -i, but with nothing after it. The CLI prints its usage text and the build terminates. -i does have an empty default - but only when it isn't passed at all.

Omitting deployItems deploys everything

The property is optional and, per the build configuration reference, defaults to all modules in sitecore.json. So deleting it to mean "deploy no items" does the exact opposite. Confirmed locally: with no -i, itemres create exits 0 and writes a package containing every module.

A filter that matches nothing is an error

The filter "include: __none__, exclude: " did not match any defined
serialization module configurations. Use the info command to see valid
module names.

Exit code 1. The CLI assumes a non-matching filter is a typo rather than an intention, so there is no sentinel value meaning "deploy nothing". And a module that does match but holds no serialized items fails differently, just as fatally:

Matched module configurations: MyProject.NoOp
Configured source item path /sitecore/templates/Feature/MyProject NoOp did not
exist in serialized items (1 subtrees) data store.

A non-resolving glob fails two ways at once

Pointing modules at a path that matches nothing looks like a plausible way to stop item deployment. Locally:

No modules were resolved with file globs, check your file globs or modules.

Every serialization command is now inert. And in the build, combined with a still-populated deployItems:

The filter "include: MyProject.*, exclude: " did not match any defined
serialization module configurations.
Build terminated due to failure
Build has failed.

Whereas the same glob with deployItems removed is the one benign outcome:

No resource packages were created since there are no items on the
filesystem. Please check your serialization configurations.

Three near-identical situations, three different behaviours. No modules at all is a warning. A filter matching no modules is an error. A matched module with no items is a different error again.

The escape hatch, and why it closed

If the build config cannot safely express "deploy no items", the alternative is to stop deploying from git and deploy a local working copy instead. Edit both files, deploy, revert.

Uploading source code is not permitted. The environment is already
linked to a branch.

dotnet sitecore cloud deployment create -id <env> --upload packages your working directory instead of pulling from the repository, and it is mutually exclusive with a branch-linked environment. The CLI offers no way to unlink - cloud environment update accepts only --name - and deployment create has no build-config override flag.

The only guidance I found for unlinking is a community blog post, which says you unlink through the environment details menu. I have not verified that myself, and as far as I can tell this restriction is not in the official documentation at all. The Deploy a project and environment page covers connecting source control when you create an environment, but says nothing about the upload restriction or how to undo it.

And in my case that door was already shut: after migrating from the legacy single-repository layout to separate editing-host repositories, the option to deselect the branch is no longer available in the Deploy app.

So: the environment cannot be unlinked, --upload can never be used, and there is no way to deploy a locally-modified configuration to it. What remains is branch-per-environment - a long-lived branch carrying a divergent sitecore.json and xmcloud.build.json, with all the merge pain that implies.

What the architecture should have been

Worth noting that Sitecore Accelerate does not suggest varying the build config per environment at all. Its model is one artifact promoted upward: every commit to main triggers CI and then a deployment to the lowest environment, and that deployment is promoted through environments until it is ready for production. Configuration identical everywhere by design, with cloud environment promote to move it up. Branch-per-environment shows up only as an aside, for teams that specifically need it.

Which reframes the whole thing. The fault is not the config syntax. It is an environment holding two incompatible roles - item source of truth and deployment target. The fix is architectural: a separate lowest environment that receives deployments, and keep the authoring environment out of the deployment path entirely.

I got there by way of five error messages. You can just start there :-)

deployItems turns your serialized items into read-only resources, and there is no safe way to say "deploy no items". Don't make your authoring environment a deployment target.

Bonus: four smaller traps found along the way

  • An invalid allowedPushOperations value silently disables all module discovery. A module file with "allowedPushOperations": "CreateOnly" made ser info return nothing at all - no error, no warning, and not just for that module. All six otherwise-valid modules vanished. Valid values include CreateAndUpdate and CreateUpdateAndDelete.

  • Include names must be unique across modules sharing a folder.

    There are several modules (MyProject.MediaLibrary and MyProject.Layout.Renderings)
    located along the path ".../authoring/items" with the same include name
    ("myproject-components"). To fix that you should split those modules into folders.

    Uniqueness is scoped by the module file's directory, not by its items.path. Since the same logical root name legitimately appears under templates, branches, settings, renderings and media, a flat layout collides. One folder per module, each with "items": { "path": "." }, fixes it.

  • -i and -n are easy to swap, and both exist. On ser pull, -i/--include filters modules and -n/--environment-name selects the environment (and leaving -n out has its own quirk, see this earlier post). Separately, ser explain needs -p/--path - the path is not positional.

  • Git Bash mangles Sitecore paths. MSYS path conversion rewrites a leading /sitecore/... into C:/Program Files/Git/sitecore/.... Set MSYS_NO_PATHCONV=1, or just use PowerShell.

Still open

One thing I have not tested: whether redeploying with no item package removes resource files already present on an environment, or merely stops adding new ones. That determines whether an affected environment heals itself or needs rebuilding. If you know, I would like to hear it.

Versions

Sitecore CLI 6.0.23, Sitecore.DevEx.Extensibility.XMCloud 1.1.120, .NET SDK 10.

References