Pipelines/Steps/Install/OnPrem/Sitecore/XM/Solr/9.2/custom-solr.json

{
    "Parameters": {
        "SolrUrl": {
            "Type": "string",
            "DefaultValue": "https://localhost:8983/solr",
            "Description": "The Solr instance url."
        },
        "SolrRoot": {
            "Type": "string",
            "DefaultValue": "c:\\solr-7.2.1",
            "Description": "The file path to the Solr instance."
        },
        "SolrService": {
            "Type": "string",
            "DefaultValue": "Solr-7.2.1",
            "Description": "The name of the Solr service."
        },
        "BaseConfig": {
            "Type": "string",
            "DefaultValue": "_default",
            "Description": "The configset to copy as a base for each core."
        },
        "CorePrefix": {
            "Type": "string",
            "DefaultValue": "sitecore",
            "Description": "The prefix for each of the created indexes."
        },
        "CoreName": {
            "Type": "string",
            "Description": "Name of custom core."
        }
    },
    "Variables": {
        "Solr.FullRoot": "[resolvepath(parameter('SolrRoot'))]",
        "Solr.Server": "[joinpath(variable('Solr.FullRoot'), 'server', 'solr')]",
        "Solr.BaseConfigs": "[joinpath(variable('Solr.Server'), 'configsets', parameter('BaseConfig'))]",
        "Solr.SchemaFileName": "managed-schema",
        "Solr.Xpath.SchemaRoot": "//schema",
        "Solr.Xpath.UniqueKey": "[concat(variable('Solr.Xpath.SchemaRoot'), '/uniqueKey')]",
        "Solr.UniqueField" : "_uniqueid",
        "Solr.UniqueField.Attributes": {
            "name" : "[variable('Solr.UniqueField')]",
            "type": "string",
            "indexed": "true",
            "required": "true",
            "stored": "true"
        },
        "Custom.Name": "[concat(parameter('CorePrefix'), '_', parameter('CoreName'))]",
        "Custom.Root": "[joinpath(variable('Solr.Server'), variable('Custom.Name'))]",
        "Custom.Conf": "[joinpath(variable('Custom.Root'), 'conf')]"
    },
    "Tasks": {
        "StopSolr": {
            "Description" : "Stops the Solr service if it is running.",
            "Type": "ManageService",
            "Params":{
                "Name": "[parameter('SolrService')]",
                "Status": "Stopped",
                "PostDelay": 1000
            }
        },
        "CleanCores": {
            "Description" : "Creates/clears core paths.",
            "Type": "EnsurePath",
            "Params":{
                "Clean": [
                    "[variable('Custom.Root')]"
                ]
            }
        },
        "PrepareCores": {
            "Description" : "Copies base configs into the core paths.",
            "Type": "Copy",
            "Params":[
                {
                    "Source": "[joinpath(variable('Solr.BaseConfigs'), '*')]",
                    "Destination": "[variable('Custom.Root')]"
                }
            ]
        },
        "AddSchemaUniqueKeyField": {
            "Description" : "Amends the core managed schema uniqueKey element.",
            "Type": "SetXml",
            "Params": [
                {
                    "FilePath": "[joinpath(variable('Custom.Conf'), variable('Solr.SchemaFileName'))]",
                    "Xpath":"[variable('Solr.Xpath.SchemaRoot')]",
                    "Element": "field",
                    "Attributes": "[variable('Solr.UniqueField.Attributes')]"
                }
            ]
        },
        "UpdateSchemaUniqueKey": {
            "Description" : "Amends the core managed schema uniqueKey element.",
            "Type": "SetXml",
            "Params": [
                {
                    "FilePath": "[joinpath(variable('Custom.Conf'), 'managed-schema')]",
                    "Xpath":"[variable('Solr.Xpath.UniqueKey')]",
                    "Value": "[variable('Solr.UniqueField')]"
                }
            ]
        },
        "StartSolr": {
            "Description" : "Starts the Solr service.",
            "Type": "ManageService",
            "Params":{
                "Name": "[parameter('SolrService')]",
                "Status": "Running",
                "PostDelay": 8000
            }
        },
        "CreateCores":{
            "Description" : "Tells Solr to create the new cores.",
            "Type": "ManageSolrCore",
            "Params": [
                {
                    "Action": "Create",
                    "Address": "[parameter('SolrUrl')]",
                    "Arguments": {
                        "name": "[variable('Custom.Name')]", "property.update.autoCreateFields": "false"
                        }
                    }
            ]
        }
    },
    "UninstallTasks": {
        "RemoveCores": {
            "Description": "Removes the cores and instance folders.",
            "Type": "ManageSolrCore",
            "Params": [
                {
                    "Action": "Unload",
                    "Address": "[parameter('SolrUrl')]",
                    "Arguments": {
                        "core": "[variable('Custom.Name')]",
                        "deleteInstanceDir": "true"
                    },
                    "ErrorAction": "SilentlyContinue"
                }
            ]
        }
    }
}