Editing host deployment fails when reserved environment variables are added manually


Symptoms

In SitecoreAI, a Sitecore-managed editing host deployment might fail when platform-managed environment variables are added manually in the Deploy app.

For Sitecore-managed editing hosts, certain environment variables are added automatically during deployment. If the same variables are also added manually in the Deploy app, the deployment configuration can contain duplicate or conflicting variable definitions. The affected variables can include:

The duplicate definitions can cause validation or configuration errors that prevent the editing host deployment from completing. As a result, Pages might be unavailable, and one or more of the following symptoms might occur:

The following are examples of error messages associated with this issue:

Error occurred prerendering page "/_global-error".
Failure releasing deployment
YamlDotNet.Core.YamlException: Duplicate key NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID
The order in patch list does not match $setElementOrder list.

Actions

To resolve the issue for a Sitecore-managed editing host:

  1. In the SitecoreAI Deploy app, open the affected project.
  2. Open the affected editing host, and then open Variables.
  3. Remove any manually added values for the following Sitecore-managed environment variables:
    • NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID
    • SITECORE_EDGE_CONTEXT_ID
    • SITECORE_PREVIEW_API_KEY
    • SITECORE_EDITING_SECRET
  4. Save the changes.
  5. Trigger a new editing host deployment.
  6. If the deployment fails again immediately after the variables are removed, trigger another fresh deployment.

Earlier failed deployments might temporarily leave the environment in an inconsistent state. After the conflicting variables are removed, another fresh deployment can allow the environment to recover without further configuration changes.

Note: Changes to environment variables require a rebuild or redeployment to take effect.

For Sitecore-managed editing hosts, the affected values are injected automatically during deployment and can change dynamically. Manually defining the values can cause configuration conflicts, duplicate keys, or stale authentication values.

For editing hosts hosted externally outside SitecoreAI, manual environment-variable configuration might be required. In this scenario, follow the applicable external editing host configuration documentation.