I used an official recommendation to create my automated Octopus Tentacle installation script, and the part of the interest in the script is as follows:
.\Tentacle.exe create-instance --instance "$hostname" --config "$home_path\Tentacle.config" --console
.\Tentacle.exe configure --instance "$hostname" --trust "$trusted_cert" --console
.\Tentacle.exe configure --instance "$hostname" --home "$home_path" --app "$home_path\Applications" --port $port --console
& netsh advfirewall firewall add rule name="Octopus Deploy Tentacle" dir=in action=allow protocol=TCP localport=$port
$envs_cmd = ''
foreach ($env in $environments){
$envs_cmd += "--environment=$env "
}
$roles_cmd = ''
foreach ($role in $roles){
$roles_cmd += "--role='$role' "
}
.\Tentacle.exe new-certificate --instance="$hostname" --if-blank --console
.\Tentacle.exe register-with --instance "$hostname" --server "$server" --name="$hostname" --apiKey="$api_key" $roles_cmd $envs_cmd --server-comms-port "$port" --comms-style TentaclePassive --console --force
.\Tentacle.exe service --instance "$hostname" --install --start --console
Everything works except the pre-last line
.\Tentacle.exe register-with --instance "$hostname" --server "$server" --name="$hostname" --apiKey="$api_key" $roles_cmd $envs_cmd --server-comms-port "$port" --comms-style TentaclePassive --console --force
that throws the exception:
CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Untitled3.ps1
If I print this particular line to get all the variables values, and copy/paste it to PowerShell console - it works. What withdraws my attention in the line is $roles_cmd $envs_cmd which expression should be something like:
--role="Role1" --environment="Env1" --environment="Env2"
This is the only part of the questionable line where both parameter name and its value are the expression. Can that cause this issue? How to handle that?