Environment limitations when passing 20 deployment targets


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{
[string]$EnvironmentName, #“App1 DEV”
[string]$OctopusBaseURI #http://octopus
$environmentsJSON=Invoke-WebRequest -URI “$OctopusBaseURI/api/environments” -Header @{ “X-Octopus-ApiKey” = $apiKey } -Method GET;
throw "Get-OctopusEnvironmentMachines: Failed to retrieve list of environments :: $_ "
write-host “EnvironmentMachinesURI: $($environment.links.machines)”
#Get array of environment machines
# $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;

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


Function Set-OctopusTentacleDisabled{
[string][Parameter(Mandatory=$true)]$MachineID, #“Machines-40”
[string]$OctopusBaseURI, #http://octopus
$machineJSON=Invoke-WebRequest -URI “$OctopusBaseURI/api/machines/$MachineID/” -Header @{ “X-Octopus-ApiKey” = $apiKey } -Method GET;
throw "Set-OctopusTentacleDisabled: Failed to find Tentacle ID: $MachineID :: $_ "
#$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}
    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;}
write-host "Set-OctopusTentacleDisabled: Posting changes to the MachineID to Octopus...";
    Invoke-WebRequest -URI "$OctopusBaseURI/api/machines/$($machine.id)" -Header @{ "X-Octopus-ApiKey" = $apiKey } -Method PUT -Body $bodyJson;
    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?

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!

Hi @Justin_Walsh,

Thanks for the reply, i tested and works!

1 Like