Skip to content

Instantly share code, notes, and snippets.

@JayDoubleu
Last active June 30, 2023 12:26
Show Gist options
  • Save JayDoubleu/94b3c1d66024ac5a826167dcfb38cc0f to your computer and use it in GitHub Desktop.
Save JayDoubleu/94b3c1d66024ac5a826167dcfb38cc0f to your computer and use it in GitHub Desktop.
Script to register octopus tentacle
param (
[Parameter(Mandatory = $true)][string] $serverThumbprint,
[Parameter(Mandatory = $true)][string] $serverUrl,
[Parameter(Mandatory = $true)][string] $serverApiKey,
[Parameter(Mandatory = $true)][string] $instancePort,
[Parameter(Mandatory = $true)][string] $instanceWorkerPool
)
$instanceName = $env:computerName
$instanceHostname = [System.Net.Dns]::GetHostByName(($env:computerName)).HostName
$rootDir = 'C:\Octopus'
$octopusExe = Join-Path ${env:ProgramFiles} 'Octopus Deploy\Tentacle\Tentacle.exe'
$configPath = Join-Path $rootDir 'Tentacle.config'
$appPath = Join-Path $rootDir 'Applications'
New-Item -ItemType "directory" -Path "$rootDir" -Force
Start-Transcript -Path "$rootDir\octopusWorkerRegistration_$(Get-Date -Format 'yyyyMMdd_HHmmss').log.txt"
& "$octopusExe" create-instance --instance $instanceName --config "$configPath" --console
& "$octopusExe" new-certificate --instance $instanceName --if-blank --console
& "$octopusExe" configure --instance $instanceName --reset-trust --console
& "$octopusExe" configure --instance $instanceName --home "$rootDir" --app "$appPath" --port "$instancePort" --console
& "$octopusExe" configure --instance $instanceName --trust $serverThumbprint --console
& netsh.exe advfirewall firewall add rule "name=Octopus Deploy $instanceName Worker" dir=in action=allow protocol=TCP localport=$instancePort
& "$octopusExe" register-worker --instance $instanceName --server "$serverUrl" --apiKey="$serverApiKey" --comms-style TentaclePassive --workerPool $instanceWorkerPool --publicHostName $instanceHostname --console
& "$octopusExe" service --instance $instanceName --install --start --console
Stop-Transcript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment