Environment limitations when passing 20 deployment targets

usability
(Gustavo Balbino) #1

Hello,

So i’m having a problem with octopus.
i can’t understand the limitations in Environments, i have 21 deploy targets, but they only appear 20.

i execute the following script do get environment tentacles:

"Function Get-OctopusEnvironmentMachines{
Param(
[string]$EnvironmentName, #“App1 DEV”
[string]$APIKey, #API-XXXXXXXXXXXXXXXXXXXXXXXXX
[string]$OctopusBaseURI #http://octopus
)
try{
$environmentsJSON=Invoke-WebRequest -URI “$OctopusBaseURI/api/environments” -Header @{ “X-Octopus-ApiKey” = $apiKey } -Method GET;
}catch{
throw "Get-OctopusEnvironmentMachines: Failed to retrieve list of environments :: $_ "
}
$environments=$environmentsJSON.content|ConvertFrom-JSON;
$environment=$($environments.items|?{$_.name.contains($EnvironmentName)})
write-host “EnvironmentMachinesURI: $($environment.links.machines)”
#Get array of environment machines
try{
# $environmentMachinesJSON=Invoke-WebRequest -URI “$OctopusBaseURI$($environment.links.machines)” -Header @{ “X-Octopus-ApiKey” = $apiKey } -Method GET;
$environmentMachinesJSON=Invoke-WebRequest -URI “$OctopusBaseURI$($environment.links.self)/machines” -Header @{ “X-Octopus-ApiKey” = $apiKey } -Method GET;

}catch{
    throw "Get-OctopusEnvironmentMachines: Failed to retrieve list of environment machines :: $_ "
}
$environmentMachines=$environmentMachinesJSON.content|ConvertFrom-JSON;
if(($environmentMachines.Items -eq $null) -or ($environmentMachines.Items.count -lt 1)){
    return $false;
}else{
    return ($environmentMachines.Items | %{$_ | select ID,Name})
}

}

Function Set-OctopusTentacleDisabled{
Param(
[switch]$SetEnabled,
[string][Parameter(Mandatory=$true)]$MachineID, #“Machines-40”
[string]$APIKey, #API-XXXXXXXXXXXXXXXXXXXXXXXXX
[string]$OctopusBaseURI, #http://octopus
[switch]$DisableOctopusServer
)
try{
$machineJSON=Invoke-WebRequest -URI “$OctopusBaseURI/api/machines/$MachineID/” -Header @{ “X-Octopus-ApiKey” = $apiKey } -Method GET;
}catch{
throw "Set-OctopusTentacleDisabled: Failed to find Tentacle ID: $MachineID :: $_ "
}
$machine=$machineJSON.content|ConvertFrom-JSON;
#$machine=$($Machines.items|?{$_.id -eq $MachineID})

#Do not disable the Octopus Server's deployment agent unless the override flag is in place
if(($Machine.Name -eq "OctopusServer") -and ($DisableOctopusServer -eq $false)){return $null;}

if($SetEnabled -eq $true){
    write-host "Set-OctopusTentacleDisabled: MachineID($MachineID) Set to ENABLED";
    if($machine.IsDisabled -ne $False){$machine.IsDisabled=$False;}
    else{return $true}
}else{
    write-host "Set-OctopusTentacleDisabled: MachineID($MachineID) Set to DISABLED";
    if(($machine.IsDisabled -ne $null) -and ($machine.IsDisabled -ne $True)){$machine.IsDisabled=$True;}
    else{return $true;}
}
$bodyJson=($machine|ConvertTo-JSON);
write-host "Set-OctopusTentacleDisabled: Posting changes to the MachineID to Octopus...";
try{
    Invoke-WebRequest -URI "$OctopusBaseURI/api/machines/$($machine.id)" -Header @{ "X-Octopus-ApiKey" = $apiKey } -Method PUT -Body $bodyJson;
}catch{
    throw "Set-OctopusTentacleDisabled: Failed to set the MachineID ($MachineID):: $_"
}

}

$apikey = “xxxxx”
$headers = @{“X-Octopus-ApiKey”=$apikey}
$octopusurl = “xxxxx”

$envName = “xxx”

#Get List of Machines
$EMachines=Get-OctopusEnvironmentMachines -EnvironmentName $envName -APIKey $apikey -OctopusBaseURI $octopusurl"

this gives me the list of deployment targets in my env.
In this env i have 21 deployment tentacles, but this only list me 20.

There is some kind of limitation for each env?

(Justin Walsh) #3

Hi @gustavo.balbino!

Thankfully, this is an easy solution, by default, we page at 20 results on this endpoint. You can overwrite this limit by using ?take=<somehighernumber> at the end of your API call, so something like:
https://YOUR_OCTOPUS/api/environments/Environments-181/machines?take=200 to get all of your targets.

I hope this helps - please don’t hesitate to reach out if you have any further questions!

(Gustavo Balbino) #4

Hi @Justin_Walsh,

Thanks for the reply, i tested and works!