Octopus.Script exported 2016-12-09 by marekgd belongs to ‘Windows’ category.
Create Windows Service
Parameters
When steps based on the template are included in a project’s deployment process, the parameters below can be set.
Service name
ServiceName = Required
Service name
Binary path
BinaryPath = Required
Executable path
Depends On
DependsOn
Depends On
Display name
DisplayName = Required
Display name
Startup type
StartupType = Required
Startup type: Boot, System, Automatic, Manual, Disabled
Description
Description = Required
Description
Script body
Steps based on this template will execute the following PowerShell script.
$serviceName = $OctopusParameters['ServiceName']
$binaryPath = $OctopusParameters['BinaryPath']
$dependsOn = $OctopusParameters['DependsOn']
$displayName = $OctopusParameters['DisplayName']
$startupType = $OctopusParameters['StartupType']
$description = $OctopusParameters['Description']
Write-Output "Creating $serviceName..."
$serviceInstance = Get-Service $serviceName -ErrorAction SilentlyContinue
if ($serviceInstance -eq $null)
{
New-Service -Name $serviceName -BinaryPathName $binaryPath -DependsOn $dependsOn -DisplayName $displayName -StartupType $startupType -Description $description
Write-Output "Service $serviceName created."
}
else
{
Write-Output "The $serviceName already exist."
}
Provided under the Apache License version 2.0.
To use this template in Octopus Deploy, copy the JSON below and paste it into the Library → Step templates → Import dialog.
{
"Id": "ba50bddb-67ec-4105-a909-134e73905b03",
"Name": "Windows Service - Create",
"Description": "Create Windows Service",
"Version": 5,
"ExportedAt": "2016-12-09T13:30:58.513Z",
"ActionType": "Octopus.Script",
"Author": "marekgd",
"Parameters": [
{
"Id": "df79a6f8-bcd2-49c9-ad3e-e49b7c838a12",
"Name": "ServiceName",
"Label": "Service name",
"HelpText": "Service name",
"DefaultValue": "Required",
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
},
"Links": {}
},
{
"Id": "cb9c4a02-0e50-43d8-bca7-f8b006f8b7a1",
"Name": "BinaryPath",
"Label": "Binary path",
"HelpText": "Executable path",
"DefaultValue": "Required",
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
},
"Links": {}
},
{
"Id": "d6acf911-8173-460d-be24-b9b31b69a3cd",
"Name": "DependsOn",
"Label": "Depends On",
"HelpText": "Depends On",
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
},
"Links": {}
},
{
"Id": "d0b86504-d2d5-4673-9043-2c968055de41",
"Name": "DisplayName",
"Label": "Display name",
"HelpText": "Display name",
"DefaultValue": "Required",
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
},
"Links": {}
},
{
"Id": "85315ed9-3b9a-493e-9379-558953105384",
"Name": "StartupType",
"Label": "Startup type",
"HelpText": "Startup type:\nBoot, System, Automatic, Manual, Disabled",
"DefaultValue": "Required",
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
},
"Links": {}
},
{
"Id": "111791c5-9d42-4ace-8a6c-9f15775db745",
"Name": "Description",
"Label": "Description",
"HelpText": "Description",
"DefaultValue": "Required",
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
},
"Links": {}
}
],
"Properties": {
"Octopus.Action.Script.Syntax": "PowerShell",
"Octopus.Action.Script.ScriptSource": "Inline",
"Octopus.Action.RunOnServer": "false",
"Octopus.Action.Script.ScriptBody": "$serviceName = $OctopusParameters['ServiceName']\n$binaryPath = $OctopusParameters['BinaryPath']\n$dependsOn = $OctopusParameters['DependsOn']\n$displayName = $OctopusParameters['DisplayName']\n$startupType = $OctopusParameters['StartupType']\n$description = $OctopusParameters['Description']\n\nWrite-Output \"Creating $serviceName...\"\n\n$serviceInstance = Get-Service $serviceName -ErrorAction SilentlyContinue\nif ($serviceInstance -eq $null)\n{\n New-Service -Name $serviceName -BinaryPathName $binaryPath -DependsOn $dependsOn -DisplayName $displayName -StartupType $startupType -Description $description\n Write-Output \"Service $serviceName created.\"\n}\nelse\n{\n Write-Output \"The $serviceName already exist.\"\n}\n",
"Octopus.Action.Script.ScriptFileName": null,
"Octopus.Action.Package.FeedId": null,
"Octopus.Action.Package.PackageId": null
},
"Category": "Windows",
"HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/windows-service-create.json",
"Website": "/step-templates/ba50bddb-67ec-4105-a909-134e73905b03",
"Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADNQTFRF////Da3qSsLvhtb0wur6O7zuWcfxldv2aMzyK7ftpOD3s+X48Pr+0fD7d9HzHLLr4fX8xD/OcwAAAaNJREFUeNrs3cFygjAUQFECWott1f//2sJoW6kIKEzNs+euXOmcmSSGDa8oJEmSJEmSJGmsj1W1K9cpsGD1Vr2WdToVEPC+2lYvZfpVrEW0qZpF1F+MRdRugzoNlvkiarfBPk0pT8GhWUSX2yASpDlLr2+DEJBmEY1ug6whx7N0n2b30G1QlmmxHsRYp6X76yvF9vg5RYQczq8UVURI35UiFmTgShED0p6lI1eKzCHTrxS5Qk6PZ9PLDtJ9PIsJmXWlyAky6/dAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQMJCyjltF/iO3gpJUpD8s4OAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgID8T8itwwKyhbTdMr4ha8hXUwZqhICcOgyNOIkE+V5wo4MSgr1u/fp7poO+AL8K/gL8yw0UeyRB34m9iQ/pVD8L5JYTO3NI58R+AsiEEzsW5OfE3sUe/zRwYkeGnG2g2CPS7rhjF4GKP0ZwyoldxK37kFqEL/7wU0mSJEmSJOmJ+xRgAHxZTCXGdZkfAAAAAElFTkSuQmCC",
"$Meta": {
"Type": "ActionTemplate"
}
}
Page updated on Friday, December 9, 2016