22 October, 2024
Sitecore XM Cloud CLI Cheatsheet updated
15 February, 2024
Sitecore XM Cloud CLI New Feature - Organization command
cloud organization info
cloud organization health
cloud organization license
27 September, 2023
Creating an XM Cloud Project from an Existing Sitecore Solution in Bitbucket
11 September, 2023
XM Cloud: Sync Content between Environments
To sync content between XM Cloud Environments, SCS (Sitecore Content Serialization) is the preferred way when compared to old way of moving content using Sitecore Content Packages. In this article, we will move content from one environment to another by an easy way.
Scenario:
Two environments: DEV and PROD
Content Sync: Copy from PROD to DEV or Copy from PROD to Local
Content to be copied:
- /sitecore/content/samplesite/samplesite/Home
- /sitecore/content/samplesite/samplesite/Data
Sitecore Content Serialization (SCS) is a system for serializing, sharing, and deploying content items, as well as keeping them in version control.
Ref: https://doc.sitecore.com/xmc/en/developers/xm-cloud/sitecore-content-serialization.html |
The flow is to connect to PROD, DEV and Local (if planning to sync it to local) environment using CLI connect command and then use CLI serialization command to pull from source Environment to target Environment.
Step 1: Connect to Environments
Before we connect to XM Cloud Environments, it is important that Sitecore CLI with plugins are installed. XM Cloud Environment IDs are needed to connect. Use CLI connect command with --allow-write flag to enable read/write access for environments.
PROD ID: 1rg2Cn4Nz9HlMvJDoMlp0R
DEV ID: 5uQrDqtEeitxTlNdOCTmwM
Step 2: Add Serialization Module to Content Sync Purpose
In order to sync only a specific set of content, it is optional to create a separate serialization module json file. In our scenario, we are pulling only the pages and the data folder. Create a module json with the below includes.
Step 3: Pull Content from Source Environment
Using CLI Serialization command, pull the content by targeting only our content sync module.
Step 4: Push Content to Target Environment
29 August, 2023
XM Cloud CLI Plugin Commands
25 August, 2023
XM Cloud - Deployment in Queue will be started immediately if an in-progress deployment is cancelled
07 July, 2022
Sitecore CLI Installation Failure or Wrong Version Installed
Recently developers are facing issues when installing Sitecore CLI. Or it may install version 5.0.16 which is not released officially.
PS C:\Project\Working\cli1> dotnet tool install --add-source=https://sitecore.myget.org/F/sc-packages/api/v3/index.json sitecore.cli
You can invoke the tool from this directory using the following commands: 'dotnet tool run sitecore' or 'dotnet sitecore'.
Tool 'sitecore.cli' (version '5.0.16') was successfully installed. Entry is added to the manifest file C:\Project\Working\cli1\.config\dotnet-tools.json.
error NU1202: Package sitecore.cli 5.0.16 is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1) / any. Package sitecore.cli 5.0.16 supports: net6.0 (.NETCoreApp,Version=v6.0) / any
The tool package could not be restored.
Tool 'sitecore.cli' failed to install. This failure may have been caused by:
* You are attempting to install a preview release and did not use the --version option to specify the version.
* A package by this name was found, but it was not a .NET Core tool.
* The required NuGet feed cannot be accessed, perhaps because of an Internet connection problem.
* You mistyped the name of the tool.
For more reasons, including package naming enforcement, visit https://aka.ms/failure-installing-tool
Sitecore Official release version for Sitecore CLI as of July 7th 2022 is 4.2.1. Unofficially Sitecore published Sitecore CLI 5.0 as they are testing the new features.
Anyone who installs Sitecore CLI without a specific version will get v5.0. Add version parameter to install the specific version to avoid this issue.
dotnet tool install --add-source=https://sitecore.myget.org/F/sc-packages/api/v3/index.json sitecore.cli --version 4.2.1
04 June, 2022
Create, package and publish a Sitecore CLI Plugin
We (SitecoreWarriors) had a chance to participate in Sitecore Hackathon 2022 and we peeked into how the Sitecore's official plugins are created and how a new plugin can be created using Extensibility package provided by Sitecore. In this article, I wanted to explain few steps to create a new plugin, package it and publish it to nuget.org or any other private package manager.
- Create Plugin Project - .NET Core Class Library
- Create Management Service - .NET Framework 4.8 Class Library
- Package and Publish Plugin
- In order to create a plugin, we need to create a .NET Core Class Library.
- Project type should be Microsoft.NET.Sdk.
- From Sitecore Package source, add the following packages.
- Sitecore.Devex.Client.Cli.Extensibility
- This package helps to create an extension to the Sitecore CLI
- Adds base for SubCommand options
- Sitecore.DevEx.Serialization.Client
- Enables us to use SitecoreApiClient which helps to send and receive response from Sitecore through management service.
- Helps to generate the API request along with access token and send it to Sitecore.
- Not sure why but Sitecore may move this piece out of Serialization Client package and create it as a standalone package to avoid this dependency.
- Next step is to implement ISitecoreCliExtension interface which will let us to register Commands. As part of this sample application, we are trying to create a Job plugin which can retrieve the jobs list from Sitecore.
- Then we can create new SubCommand class inheriting SubcommandBase from Sitecore.Devex.Client.Cli.Extensibility package. This will let us to override the handle method to implement the logic to call Sitecore API for this SubCommand.
- In the SubCommand implementation, use SitecoreApiClient and trigger the request to Sitecore Management API.
- Sitecore Management Service gets the request from CLI and execute the request in Sitecore Context.
- Authentication token obtained from CLI login is sent as part of the Bearer token.
- Depending upon the solution, the dependencies changes. In this case, we needed Sitecore.Kernel, Sitecore.DependencyInjection package.
- Management services uses GraphQL. Queries and Mutations.
Queries are the GraphQL equivalent toGET
calls in REST. mutations represent the state-changing methods in REST (likeDELETE
,PUT
,PATCH
, etc). - In this example, we are just getting Jobs list. So we can go with query. Implement Sitecore.Services.GraphQL.Schemas.SchemaProviderBase from Sitecore.Services.GraphQL and override CreateRootQueries which in turn returns the data to be returned to CLI. Logic is get the jobs list from JobManager and return the results.
- Build the class library along with configuration and package it as Sitecore Package to be installed via Installation Wizard.
- using nuget.exe CLI.
- using NuGet Package Explorer GUI.
- We need to prepare the package content. Package should have the plugin library (.dll). Please note that DLL name and the plugin name should match otherwise we may get errors. Refer this article for more details - Sitecore CLI Extension Development - Possible errors and solution.
- Once the NuGet Package Explorer is downloaded and opened, choose Create a new package.
- Go to Edit menu and click Edit Metadata.
- Add the plugin name in the ID field
- Create a new folder called plugin
- Add plugin class library and few other assemblies like Sitecore.DevEx.Serialization.Client and Microsoft.Extensions.Http to the plugin folder.
- Go to nuget.org, create a new account, login to the account, click on your username and go to API keys.
- Create a new API key. Provide a key name and click create. Copy the generated key and save it securely.
- Go back to the NuGet package explorer, go to File and click Publish. Enter the copied API key in the Publish Key or PAT field and then click publish. It should be published immediately and it may take 10 minutes for the package to be available in the nuget.org search results.
- Install the management service package created in the second step in Sitecore CM using installation wizard.
- Once the package is available in nuget.org search results, you can login to CLI using dotnet sitecore login.
- Install the plugin using dotnet sitecore plugin add -n SitecorePlugin.Custom and plugin will be installed in your workstation.
22 March, 2022
Sitecore CLI - Authentication and Authorization
- Interactive User Login
- Sitecore Username and Password are needed.
- Used mostly by the developers.
- Non-Interactive Client Login
- Client ID and Client Secret are needed.
- Client should be configured in Identity server and Identity provider should be configured in Content Management as documented.
- Used for CI/CD process to automate tasks.
- Identity server is must.
- The result of the authentication and authorization is access token. If we wanted extended expiry of tokens for a longer running process, we can opt for refresh token.
21 March, 2022
Sitecore CLI Extension Development - Possible errors and solution
While we (Sitecore Warriors) were working on creating Sitecore CLI extension in Sitecore Hackathon, we came across few errors and I would like to share it in this article.
- Could not locate plugin SitecoreWarriors.DevEx.Extensibility.Jobs@4.1.1. Some CLI commands may not function correctly.
To speed up the development and testing the plugin, we can manually place the plugin assembly in /.sitecore/package-cache/nuget/PluginName and add the plugin name in the sitecore.json file.
Possible Reason 1: If the assembly name and plugin name do not match, then we will get this error. Once we set the same name for plugin as well the assembly name, the dotnet sitecore -h command will list the plugin.
Possible Reason 2: If the nuget package or the plugin assembly is not placed inside a folder called plugin, you will get this error.PS C:\Project\Working\CLI> dotnet sitecore -h >> Begin installing NuGet packages: SitecoreWarriors.DevEx.Extensibility.Jobs@4.1.1 >>> Skipping NuGet package SitecoreWarriors.DevEx.Extensibility.Jobs@4.1.1 because it is already installed. Could not locate plugin SitecoreWarriors.DevEx.Extensibility.Jobs@4.1.1. Some CLI commands may not function correctly.
- Plugin does not supported by the current version of the CLI. Please try to update you CLI
Plugin product should be .NET Core project. If the plugin assembly project is created as a Web SDK (Microsoft.NET.Sdk.Web) project instead of just an SDK project, CLI will not be able to recognize the plugin. Make sure the project type is Microsoft.NET.Sdk.
15 March, 2022
Job Plugin - Sitecore CLI Plugin - Sitecore Hackathon 2022
- View currently running, queued and finished jobs. Also lists configured Sitecore Database jobs.
- Execute Sitecore Database jobs on-demand
- Rebuild the Link database
- Plugin (published in nuget.org)
- Sitecore Management Service to initiate the action in Sitecore Context.
- Sitecore instance (10.2) with Sitecore Management Services package installed. Setup a project folder in your workstation. Install and initiate the Sitecore CLI as mentioned in this document.
- As part of this job plugin, we have created a management service which can receive the request from the CLI and execute the action in Sitecore. The management service package is placed here. This package can be installed using Sitecore Installation Wizard.
- To install the job plugin, Sitecore has provided a plugin called plugin. You can pass on the plugin name along with add subcommand. Please note that this plugin is already published to nuget.org here.
dotnet sitecore plugin add -n SitecoreWarriors.DevEx.Extensibility.Jobs - To verify whether job plugin has been installed successfully, you can run dotnet sitecore job -h.
dotnet sitecore job [subcommand] [options]
- list - Get all jobs list (running, queued, finished and db task jobs). Db task can be started on-demand.
- rebuildlinkdb - Start rebuilding a link db.
- start - Start a DB task.
Option | Explanation |
---|---|
-c, --config (config) | Path to root sitecore.json directory (default: cwd) |
-v, --verbose | Write some additional diagnostic and performance data |
-t, --trace | Write more additional diagnostic and performance data |
-?, -h, --help | Show help and usage information |
Option | Explanation |
---|---|
-c, --config (config) | Path to root sitecore.json directory (default: cwd) |
-j, --job-name (job-name) | Mention DB Task Schedule Name from Listing. |
-v, --verbose | Write some additional diagnostic and performance data |
-t, --trace | Write more additional diagnostic and performance data |
-?, -h, --help | Show help and usage information |
Option | Explanation |
---|---|
-c, --config (config) | Path to root sitecore.json directory (default: cwd) |
-db, --database (database) | Mention DB name for rebuilding the link DB (default: master) |
-v, --verbose | Write some additional diagnostic and performance data |
-t, --trace | Write more additional diagnostic and performance data |
-?, -h, --help | Show help and usage information |
- Install the job Sitecore management service package.
- In order for Sitecore CLI to interact with Sitecore Management Services, we need to login and obtain the access token.
dotnet sitecore login
- Install the job plugin.
dotnet sitecore plugin add -n SitecoreWarriors.DevEx.Extensibility.Jobs - Get the list of commands in job plugin.
dotnet sitecore job -h - To view the list of running, queued, finished and DB tasks.
dotnet sitecore job list - To start a DB task. The last run changes once the job gets executed.
dotnet sitecore job start -j {JobName} - To rebuild the link database.
dotnet sitecore job rebuildlinkdb -db master