diff --git a/step-templates/octopus-check-roles.json b/step-templates/octopus-check-roles.json index 6f63e447f..065c8d498 100644 --- a/step-templates/octopus-check-roles.json +++ b/step-templates/octopus-check-roles.json @@ -3,7 +3,7 @@ "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, + "Version": 2, "CommunityActionTemplateId": null, "Packages": [], "GitDependencies": [], @@ -11,7 +11,7 @@ "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}" + "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 Write-Highlight \"See the [Octopus documentation](https://octopus.com/docs/octopus-rest-api/how-to-create-an-api-key) for details on creating API keys.\"\n Write-Highlight \"Once you have an API key, add it to the $($OctopusParameters['Octopus.Step.Name']) step to enable the ability to check for targets in this space.\"\n }\n\n Set-OctopusVariable -Name SetupValid -Value $setupValid\n} catch {\n Write-Verbose \"Fatal error occurred:\"\n Write-Verbose \"$($_.Exception.Message)\"\n}" }, "Parameters": [ {