Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions step-templates/octopus-check-roles.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"Id": "81444e7f-d77a-47db-b287-0f1ab5793880",
"Name": "Octopus - Check Targets Available",
"Description": "Checks for the presence of targets with the specified tag. If no targets are found, the deployment will fail with the provided message.",
"ActionType": "Octopus.Script",
"Version": 1,
"CommunityActionTemplateId": null,
"Packages": [],
"GitDependencies": [],
"Properties": {
"OctopusUseBundledTooling": "False",
"Octopus.Action.Script.ScriptSource": "Inline",
"Octopus.Action.Script.Syntax": "PowerShell",
"Octopus.Action.Script.ScriptBody": "$errorCollection = @()\n$setupValid = $false\n\nWrite-Host \"Checking for deployment targets ...\"\n\ntry\n{\n # Check to make sure targets have been created\n if ([string]::IsNullOrWhitespace(\"#{Octopus.Web.ServerUri}\"))\n {\n $octopusUrl = \"#{Octopus.Web.BaseUrl}\"\n }\n else\n {\n $octopusUrl = \"#{Octopus.Web.ServerUri}\"\n }\n\n $apiKey = \"#{CheckTargets.Octopus.Api.Key}\"\n $role = \"#{CheckTargets.Octopus.Role}\"\n $message = \"#{CheckTargets.Message}\"\n\n if (![string]::IsNullOrWhitespace($apiKey) -and $apiKey.StartsWith(\"API-\"))\n {\n $spaceId = \"#{Octopus.Space.Id}\"\n $headers = @{ \"X-Octopus-ApiKey\" = \"$apiKey\" }\n\n try\n {\n $roleTargets = Invoke-RestMethod -Method Get -Uri \"$octopusUrl/api/$spaceId/machines?roles=$role\" -Headers $headers\n if ($roleTargets.Items.Count -lt 1)\n {\n $errorCollection += @(\"Expected at least 1 target for tag $role, but found $( $roleTargets.Items.Count ). $message\")\n }\n }\n catch\n {\n $errorCollection += @(\"Failed to retrieve role targets: $( $_.Exception.Message )\")\n }\n\n if ($errorCollection.Count -gt 0)\n {\n foreach ($item in $errorCollection)\n {\n Write-Highlight \"$item\"\n }\n }\n else\n {\n $setupValid = $true\n Write-Host \"Setup valid!\"\n }\n }\n else\n {\n Write-Highlight \"The project variable CheckTargets.Octopus.Api.Key has not been configured, unable to check deployment targets.\"\n }\n\n Set-OctopusVariable -Name SetupValid -Value $setupValid\n} catch {\n Write-Verbose \"Fatal error occurred:\"\n Write-Verbose \"$($_.Exception.Message)\"\n}"
},
"Parameters": [
{
"Id": "e9713772-81f8-4f0f-af80-10c3ec0bfb17",
"Name": "CheckTargets.Octopus.Api.Key",
"Label": "Octopus API Key",
"HelpText": "The API key used to query the Octopus instance.",
"DefaultValue": "",
"DisplaySettings": {
"Octopus.ControlType": "Sensitive"
}
},
{
"Id": "f2c126ad-e907-4fb8-84a3-a5fb80dd6688",
"Name": "CheckTargets.Octopus.Role",
"Label": "Target Tag to Check",
"HelpText": "The name of the target tag to check for.",
"DefaultValue": "",
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
},
{
"Id": "2d5257e4-288a-456c-ba18-bd2b3c1c1351",
"Name": "CheckTargets.Message",
"Label": "Message to display if tags not found",
"HelpText": "An optional custom message to display if no targets are found with the specified tag.",
"DefaultValue": "",
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
}
],
"StepPackageId": "Octopus.Script",
"$Meta": {
"ExportedAt": "2025-10-13T00:52:34.019Z",
"OctopusVersion": "2025.3.14357",
"Type": "ActionTemplate"
},
"LastModifiedBy": "mcasperson",
"Category": "Octopus"
}