Pages

15 March, 2022

Job Plugin - Sitecore CLI Plugin - Sitecore Hackathon 2022

Sitecore Hackathon is a community driven event and we (Sitecore Warriors) chose idea Extend Sitecore CLI.

We chose many ideas and finally ended up completing Job related plugin. 

This Sitecore Job plugin will enable developers/admins to
  1. View currently running, queued and finished jobs. Also lists configured Sitecore Database jobs.
  2. Execute Sitecore Database jobs on-demand
  3. Rebuild the Link database
There are two parts in developing a Sitecore CLI Plugin. 
  1. Plugin (published in nuget.org)
  2. Sitecore Management Service to initiate the action in Sitecore Context.

Installation instructions:
  1. 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
  2. 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. 
  3. 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
  4. To verify whether job plugin has been installed successfully, you can run dotnet sitecore job -h
Usage:
dotnet sitecore job [subcommand] [options]
Subcommands:

You can use the following subcommands:
  1. list - Get all jobs list (running, queued, finished and db task jobs). Db task can be started on-demand.
  2. rebuildlinkdb - Start rebuilding a link db.
  3. start - Start a DB task.
Options:

You can use the following options with the list subcommand:

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

You can use the following options with the start subcommand:

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

You can use the following options with the rebuildlinkdb subcommand:

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

Demo:

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


Sitecore CLI is a powerful tool to automate admin tasks and integrate it as part of DevOps. Since additional plugins can be added easily, this tool can integrate not only with Sitecore XM/XP, it can be leveraged for other Sitecore product family with few customization. 

No comments:

Post a Comment

blockquote { margin: 0; } blockquote p { padding: 15px; background: #eee; border-radius: 5px; } blockquote p::before { content: '\201C'; } blockquote p::after { content: '\201D'; }