Octopus.Script exported 2018-03-09 by Verzada belongs to ‘Octopus’ category.
This step downloads the latest version of Octopus Server and upgrades an existing instance. Run this step on a tentacle that has privileges to install software and start/stop services on the target server.
Run this after a database backup step
To Use:
- Install a tentacle on the Octopus Server machine with privileges to install software and start/stop services
- Add that tentacle to an environment and with a unique role
- Setup a project for the upgrade process
- Add a database backup step for your Octopus Server database
- Add this step, selecting it to run on just the role previously configured
- Create a release
- Deploy that release whenever an upgrade is needed
NB: The deployment will show as “Timed Out” when the server comes back online
Parameters
When steps based on the template are included in a project’s deployment process, the parameters below can be set.
Instance Name
InstanceName = OctopusServer
The name of your octopus instance. For the default instance use OctopusServer
.
InstallPath
InstallPath = C:\Program Files\Octopus Deploy\Octopus
The installation path to Octopus Deploy Server. Not the instance directory
Version number of Octopus Server which is going to be installed
SpecificOctopusServerVersionToInstall =
Selects a specific version of Octopus Server to install. This is especially handy for a downgrade. The version number must be valid though.
Script body
Steps based on this template will execute the following PowerShell script.
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Function GetLatestVersionOrSpecificVersionOfOctopusServer()
{
if([string]::IsNullOrEmpty($SpecificOctopusServerVersionToInstall))
{
Write-Host "No specific version has been selected, getting latest version from octopusdeploy.com"
$versions = Invoke-WebRequest https://octopusdeploy.com/download/upgrade/v3 -UseBasicParsing | ConvertFrom-Json
$version = $versions[-1].Version
return $version
}
else
{
Write-Host "Specific version has been selected"
return $SpecificOctopusServerVersionToInstall
}
}
Function GetCurrentlyInstalledVersionOfOctopusServer()
{
$InstalledVersion = (get-item "$InstallPath\Octopus.Server.exe").VersionInfo.fileversion
return $installedVersion
}
Function DownloadOctopusServer([string] $versionNumber)
{
Write-Host "Downloading Octopus Server version $versionNumber"
$tempFile = [System.IO.Path]::GetTempFileName()
try
{
(New-Object System.Net.WebClient).DownloadFile("https://download.octopusdeploy.com/octopus/Octopus.$versionNumber-x64.msi", $tempFile)
}
catch
{
Write-Host "Exception occurred"
echo $_.Exception|format-list -force
}
Write-Host "Download completed"
return $tempFile
}
Function StopOctopusServer()
{
Write-Host "Stopping Server"
. "$InstallPath\Octopus.Server.exe" service --stop --console --instance $InstanceName
}
Function InstallOctopusServer([object] $tempFile)
{
Write-Host "Installing ..."
msiexec /i $tempFile /quiet | Out-Null
}
Function RemoveTempFile([object] $temporaryFile)
{
Write-Host "Deleting downloaded installer"
Remove-Item $temporaryFile
}
Function StartOctopusServer()
{
Write-Host "Starting Octopus Server"
. "$InstallPath\Octopus.Server.exe" service --start --console --instance $InstanceName
}
Function InstallSetVersionOnOctopusServer([string] $currentlyInstalledVersion, [string] $selectedVersionToInstall){
Write-Host "Currently installed version: $currentlyInstalledVersion"
Write-Host "Selected version to install: $selectedVersionToInstall"
$tempFile = DownloadOctopusServer $selectedVersionToInstall
StopOctopusServer
InstallOctopusServer $tempFile
RemoveTempFile $tempFile
StartOctopusServer
}
Function StartInstallationOfOctopusServer () {
## Get the current state of Octopus Server
$selectedVersionToInstall = GetLatestVersionOrSpecificVersionOfOctopusServer
$currentlyInstalledVersion = GetCurrentlyInstalledVersionOfOctopusServer
if([version]$selectedVersionToInstall -eq [version]$currentlyInstalledVersion)
{
Write-host "Octopus Server has already been installed with version $currentlyInstalledVersion"
}
else
{
InstallSetVersionOnOctopusServer $currentlyInstalledVersion $selectedVersionToInstall
}
}
StartInstallationOfOctopusServer
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": "4b3a1f09-1827-41bb-88a4-894c6317922b",
"Name": "Upgrade Octopus Server",
"Description": "This step downloads the latest version of Octopus Server and upgrades an existing instance. Run this step on a tentacle that has privileges to install software and start/stop services on the target server.\n\n**Run this after a database backup step**\n\nTo Use:\n- Install a tentacle on the Octopus Server machine with privileges to install software and start/stop services\n- Add that tentacle to an environment and with a unique role\n- Setup a project for the upgrade process\n- Add a database backup step for your Octopus Server database\n- Add this step, selecting it to run on just the role previously configured\n- Create a release\n- Deploy that release whenever an upgrade is needed\n\nNB: The deployment will show as \"Timed Out\" when the server comes back online",
"Version": 10,
"ExportedAt": "2018-03-09T15:07:55.181Z",
"ActionType": "Octopus.Script",
"Author": "Verzada",
"Parameters": [
{
"Id": "41442ee8-d56a-4a03-8c4b-af4c02245d9e",
"Name": "InstanceName",
"Label": "Instance Name",
"HelpText": "The name of your octopus instance. For the default instance use `OctopusServer`.",
"DefaultValue": "OctopusServer",
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
},
"Links": {}
},
{
"Id": "18ede5ad-24a8-4796-a6e2-1b49a4cd7df2",
"Name": "InstallPath",
"Label": "InstallPath",
"HelpText": "The installation path to Octopus Deploy Server. Not the instance directory",
"DefaultValue": "C:\\Program Files\\Octopus Deploy\\Octopus",
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
},
"Links": {}
},
{
"Id": "098375bf-ff27-47c3-93ce-0191aade1b21",
"Name": "SpecificOctopusServerVersionToInstall",
"Label": "Version number of Octopus Server which is going to be installed",
"HelpText": "Selects a specific version of Octopus Server to install. This is especially handy for a downgrade. The version number must be valid though.",
"DefaultValue": "",
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
},
"Links": {}
}
],
"Properties": {
"Octopus.Action.Script.Syntax": "PowerShell",
"Octopus.Action.Script.ScriptSource": "Inline",
"Octopus.Action.RunOnServer": "false",
"Octopus.Action.Script.ScriptBody": "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12\n\nFunction GetLatestVersionOrSpecificVersionOfOctopusServer() \n{\n if([string]::IsNullOrEmpty($SpecificOctopusServerVersionToInstall))\n {\n Write-Host \"No specific version has been selected, getting latest version from octopusdeploy.com\"\n $versions = Invoke-WebRequest https://octopusdeploy.com/download/upgrade/v3 -UseBasicParsing | ConvertFrom-Json\n $version = $versions[-1].Version\n return $version\n }\n else \n {\n \tWrite-Host \"Specific version has been selected\"\n return $SpecificOctopusServerVersionToInstall\n }\n}\n\nFunction GetCurrentlyInstalledVersionOfOctopusServer() \n{\n $InstalledVersion = (get-item \"$InstallPath\\Octopus.Server.exe\").VersionInfo.fileversion\n return $installedVersion\n}\n\nFunction DownloadOctopusServer([string] $versionNumber) \n{ \n Write-Host \"Downloading Octopus Server version $versionNumber\"\n $tempFile = [System.IO.Path]::GetTempFileName()\n \ttry\n {\n (New-Object System.Net.WebClient).DownloadFile(\"https://download.octopusdeploy.com/octopus/Octopus.$versionNumber-x64.msi\", $tempFile)\n }\n catch\n {\n Write-Host \"Exception occurred\"\n echo $_.Exception|format-list -force\n }\n Write-Host \"Download completed\"\n return $tempFile\n}\n\nFunction StopOctopusServer() \n{\n Write-Host \"Stopping Server\"\n . \"$InstallPath\\Octopus.Server.exe\" service --stop --console --instance $InstanceName\n}\n\nFunction InstallOctopusServer([object] $tempFile)\n{\n Write-Host \"Installing ...\"\n msiexec /i $tempFile /quiet | Out-Null\n}\n\nFunction RemoveTempFile([object] $temporaryFile)\n{ \n Write-Host \"Deleting downloaded installer\"\n Remove-Item $temporaryFile\n}\n\nFunction StartOctopusServer()\n{\n Write-Host \"Starting Octopus Server\"\n . \"$InstallPath\\Octopus.Server.exe\" service --start --console --instance $InstanceName\n}\n\nFunction InstallSetVersionOnOctopusServer([string] $currentlyInstalledVersion, [string] $selectedVersionToInstall){\n\n Write-Host \"Currently installed version: $currentlyInstalledVersion\"\n Write-Host \"Selected version to install: $selectedVersionToInstall\" \n\n $tempFile = DownloadOctopusServer $selectedVersionToInstall\n StopOctopusServer\n InstallOctopusServer $tempFile\n RemoveTempFile $tempFile\n StartOctopusServer\n}\n\nFunction StartInstallationOfOctopusServer () {\n\n ## Get the current state of Octopus Server\n $selectedVersionToInstall = GetLatestVersionOrSpecificVersionOfOctopusServer \n $currentlyInstalledVersion = GetCurrentlyInstalledVersionOfOctopusServer\n\n\n if([version]$selectedVersionToInstall -eq [version]$currentlyInstalledVersion)\n {\n Write-host \"Octopus Server has already been installed with version $currentlyInstalledVersion\" \n }\n else \n {\n InstallSetVersionOnOctopusServer $currentlyInstalledVersion $selectedVersionToInstall\n }\n}\n\nStartInstallationOfOctopusServer"
},
"Category": "Octopus",
"HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/upgrade-octopus-server.json",
"Website": "/step-templates/4b3a1f09-1827-41bb-88a4-894c6317922b",
"Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAC1QTFRFT6Tl////L5Pg8vj9Y67omsvwPJrisdfzfbzs5fL7y+T32Ov5isLucLXqvt31CJPHWwAABMJJREFUeNrs3deW4jAMAFDF3U75/89dlp0ZhiU4blJEjvQ8hYubLJsA00UCBCIQgQhEIAIRiEAEIhCBCEQgAhGIQAQiEIEIhD8kJm+t+QprfdKfB9HbYpx6CWfspj8HMi+gMgHL/AmQA8W3JTKH+ALFvzCeL0RbpyoCPE9IJeNOSQwh5Z3qd6yRGWQ2qi2cZQWxqj1WzQYSjeoJmJlAklOd4VlArOqPhQEkqBERToeMcfRJBkC0Uep8CfBpjz4JsHJ0zF3dkEWNje0kiB/sUC6eApndaIiCMyAa1PiwJ0AWhRGJHJJQHG2dC7h1rNbO1QOxSA7lNCkkKrQIpJCAB1GREILYIC1NAiwbpKFJgGWDNExcwGstfExcZBCHC6nOglshHtmhViLIig1RNBCN7qjtW8C0Z1UvJcC1Z9XmwMBzzvobmgAyEzgq91dtEEsBsQSQQAFZCSBAATEEEApHZbrVBIkkEIUPSVeB+KtALA0kXQUSrwKZBCIQBnk8Y4i5CsReBeKvkqLM+BCSDWJlrZFvGk9SRTHshkgjZCGAaArIxm3H3grhVzFlW2msfl1ca79UJ1bofYvsDHHlNdTZnlh5MghuPd5NdBDUNZHyCkfktIh03XzALGRPlBDPac7qgWjHZzWcmF5zmmkhidMQ6boKiDXcDTUEaylZqCGJ0Vjvu/fLJtHqhSANEvqb2OYqkOUqEHuVMb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