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
10 changes: 5 additions & 5 deletions step-templates/automate-manual-intervention-response.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"Name": "Automate Manual Intervention Response",
"Description": "This template will search for deployments that have been paused due to Manual Intervention or Guided Failure and automate the response.",
"ActionType": "Octopus.Script",
"Version": 2,
"Version": 3,
"CommunityActionTemplateId": null,
"Packages": [],
"Properties": {
"Octopus.Action.Script.ScriptSource": "Inline",
"Octopus.Action.Script.Syntax": "PowerShell",
"Octopus.Action.Script.ScriptBody": "function Get-OctopusItems\n{\n # Define parameters\n param(\n $OctopusUri,\n $ApiKey,\n $SkipCount = 0\n )\n\n # Define working variables\n $items = @()\n $skipQueryString = \"\"\n $headers = @{\"X-Octopus-ApiKey\"=\"$ApiKey\"}\n\n # Check to see if there there is already a querystring\n if ($octopusUri.Contains(\"?\"))\n {\n $skipQueryString = \"&skip=\"\n }\n else\n {\n $skipQueryString = \"?skip=\"\n }\n\n $skipQueryString += $SkipCount\n\n # Get intial set\n $resultSet = Invoke-RestMethod -Uri \"$($OctopusUri)$skipQueryString\" -Method GET -Headers $headers\n\n # Check to see if it returned an item collection\n if ($resultSet.Items)\n {\n # Store call results\n $items += $resultSet.Items\n\n # Check to see if resultset is bigger than page amount\n if (($resultSet.Items.Count -gt 0) -and ($resultSet.Items.Count -eq $resultSet.ItemsPerPage))\n {\n # Increment skip count\n $SkipCount += $resultSet.ItemsPerPage\n\n # Recurse\n $items += Get-OctopusItems -OctopusUri $OctopusUri -ApiKey $ApiKey -SkipCount $SkipCount\n }\n }\n else\n {\n return $resultSet\n }\n\n\n # Return results\n return ,$items\n}\n\n$automaticResponseOctopusUrl = $OctopusParameters['AutomateResponse.Octopus.Url']\n$automaticResponseApiKey = $OctopusParameters['AutomateResponse.Api.Key']\n$automaticResponseReasonNotes = $OctopusParameters['AutomateResponse.Reason.Notes']\n$automaticResponseManualInterventionResponseType = $OctopusParameters['AutomateResponse.ManualIntervention']\n$automaticResponseGuidedFailureResponseType = $OctopusParameters['AutomateResponse.GuidedFailure']\n$header = @{ \"X-Octopus-ApiKey\" = $automaticResponseApiKey }\n\n# Validate response type input\nif (![string]::IsNullOrWhitespace($automaticResponseManualInterventionResponseType) -and ![string]::IsNullOrWhitespace($automaticResponseGuidedFailureResponseType))\n{\n\t# Fail step\n Write-Error \"Cannot have both a Manual Intervention and Guided Failure selections.\"\n}\n\nif ([string]::IsNullOrWhitespace($automaticResponseManualInterventionResponseType) -and [string]::IsNullOrWhitespace($automaticResponseGuidedFailureResponseType))\n{\n\t# Fail step\n Write-Error \"Please select either a Manual Intervention or Guidded Failure response type.\"\n}\n\n# Get space\n$spaceId = $OctopusParameters['Octopus.Space.Id']\n\n# Get project\n$projectId = $OctopusParameters['Octopus.Project.Id']\n\n# Get the environemtn\n$environmentId = $OctopusParameters['Octopus.Environment.Id']\n\n# Get currently executing deployments for project\nWrite-Host \"Searching for executing deployments ...\"\n$executingDeployments = Get-OctopusItems -OctopusUri \"$automaticResponseOctopusUrl/api/$($spaceId)/deployments?projects=$($projectId)&taskState=Executing&environments=$($environmentId)\" -ApiKey $automaticResponseApiKey\n\n# Check to see if anything was returned for the environment\nif ($executingDeployments -is [array])\n{\n # Loop through executing deployments\n foreach ($deployment in $executingDeployments)\n {\n # Get object for manual intervention\n Write-Host \"Checking $($deployment.Id) for manual interventions ...\"\n $manualIntervention = Get-OctopusItems -OctopusUri \"$automaticResponseOctopusUrl/api/$($spaceId)/interruptions?regarding=$($deployment.Id)&pendingOnly=true\" -ApiKey $automaticResponseApiKey\n\n # Check to see if a manual intervention was returned\n if ($null -ne $manualIntervention.Id)\n {\n # Take responsibility\n Write-Host \"Auto taking resonsibility for manual intervention ...\"\n Invoke-RestMethod -Method Put -Uri \"$automaticResponseOctopusUrl/api/$($spaceId)/interruptions/$($manualIntervention.Id)/responsible\" -Headers $header\n\n # Create response object\n $jsonBody = @{\n Notes = $automaticResponseReasonNotes\n }\n\n # Check to see if manual intervention is empty\n if (![string]::IsNullOrWhiteSpace($automaticResponseManualInterventionResponseType))\n {\n # Add the manual intervention type\n Write-Host \"Submitting $automaticResponseManualInterventionResponseType as response ...\"\n $jsonBody.Add(\"Result\", $automaticResponseManualInterventionResponseType)\n }\n\n # Check to see if the guided failure is empty\n if (![string]::IsNullOrWhiteSpace($automaticResponseGuidedFailureResponseType))\n {\n # Add the guided failure response\n Write-Host \"Submitting $automaticResponseGuidedFailureResponseType as response ...\"\n $jsonBody.Add(\"Guidance\", $automaticResponseGuidedFailureResponseType)\n }\n\n # Post to server\n Invoke-RestMethod -Method Post -Uri \"$automaticResponseOctopusUrl/api/$($spaceId)/interruptions/$($manualIntervention.Id)/submit\" -Body ($jsonBody | ConvertTo-Json -Depth 10) -Headers $header\n }\n }\n}"
"Octopus.Action.Script.ScriptBody": "function Get-OctopusItems\n{\n # Define parameters\n param(\n $OctopusUri,\n $ApiKey,\n $SkipCount = 0\n )\n\n # Define working variables\n $items = @()\n $skipQueryString = \"\"\n $headers = @{\"X-Octopus-ApiKey\"=\"$ApiKey\"}\n\n # Check to see if there there is already a querystring\n if ($octopusUri.Contains(\"?\"))\n {\n $skipQueryString = \"&skip=\"\n }\n else\n {\n $skipQueryString = \"?skip=\"\n }\n\n $skipQueryString += $SkipCount\n\n # Get intial set\n $resultSet = Invoke-RestMethod -Uri \"$($OctopusUri)$skipQueryString\" -Method GET -Headers $headers\n\n # Check to see if it returned an item collection\n if ($null -ne $resultSet.Items)\n {\n # Store call results\n $items += $resultSet.Items\n\n # Check to see if resultset is bigger than page amount\n if (($resultSet.Items.Count -gt 0) -and ($resultSet.Items.Count -eq $resultSet.ItemsPerPage))\n {\n # Increment skip count\n $SkipCount += $resultSet.ItemsPerPage\n\n # Recurse\n $items += Get-OctopusItems -OctopusUri $OctopusUri -ApiKey $ApiKey -SkipCount $SkipCount\n }\n }\n else\n {\n return $resultSet\n }\n\n\n # Return results\n return ,$items\n}\n\n$automaticResponseOctopusUrl = $OctopusParameters['AutomateResponse.Octopus.Url']\n$automaticResponseApiKey = $OctopusParameters['AutomateResponse.Api.Key']\n$automaticResponseReasonNotes = $OctopusParameters['AutomateResponse.Reason.Notes']\n$automaticResponseManualInterventionResponseType = $OctopusParameters['AutomateResponse.ManualIntervention']\n$automaticResponseGuidedFailureResponseType = $OctopusParameters['AutomateResponse.GuidedFailure']\n$header = @{ \"X-Octopus-ApiKey\" = $automaticResponseApiKey }\n\n# Validate response type input\nif (![string]::IsNullOrWhitespace($automaticResponseManualInterventionResponseType) -and ![string]::IsNullOrWhitespace($automaticResponseGuidedFailureResponseType))\n{\n\t# Fail step\n Write-Error \"Cannot have both a Manual Intervention and Guided Failure selections.\"\n}\n\nif ([string]::IsNullOrWhitespace($automaticResponseManualInterventionResponseType) -and [string]::IsNullOrWhitespace($automaticResponseGuidedFailureResponseType))\n{\n\t# Fail step\n Write-Error \"Please select either a Manual Intervention or Guided Failure response type.\"\n}\n\n# Get space\n$spaceId = $OctopusParameters['Octopus.Space.Id']\n\n# Get project\n$projectId = $OctopusParameters['Octopus.Project.Id']\n\n# Get the environment\n$environmentId = $OctopusParameters['Octopus.Environment.Id']\n\nif (![string]::IsNullOrWhitespace($automaticResponseGuidedFailureResponseType))\n{\n# Get currently executing deployments for project - this is for Guided Failure as they're in an executing state\n Write-Host \"Searching for executing deployments ...\"\n $executingDeployments = Get-OctopusItems -OctopusUri \"$automaticResponseOctopusUrl/api/$($spaceId)/deployments?projects=$($projectId)&taskState=Executing&environments=$($environmentId)\" -ApiKey $automaticResponseApiKey\n}\n\nif (![string]::IsNullOrWhitespace($automaticResponseManualInterventionResponseType))\n{\n Write-Host \"Searching for queued deployments ...\"\n # Get queued deployments - this is for \n $executingDeployments = Get-OctopusItems -OctopusUri \"$automaticResponseOctopusUrl/api/$($spaceId)/deployments?projects=$($projectId)&taskState=Queued&environments=$($environmentId)\" -ApiKey $automaticResponseApiKey\n}\n\n# Check to see if anything was returned for the environment\nif ($executingDeployments -is [array])\n{\n # Loop through executing deployments\n foreach ($deployment in $executingDeployments)\n {\n # Get object for manual intervention\n Write-Host \"Checking $($deployment.Id) for manual interventions ...\"\n $manualIntervention = Get-OctopusItems -OctopusUri \"$automaticResponseOctopusUrl/api/$($spaceId)/interruptions?regarding=$($deployment.Id)&pendingOnly=true\" -ApiKey $automaticResponseApiKey\n\n # Check to see if a manual intervention was returned\n if ($null -ne $manualIntervention.Id)\n {\n # Take responsibility\n Write-Host \"Auto taking resonsibility for manual intervention ...\"\n Invoke-RestMethod -Method Put -Uri \"$automaticResponseOctopusUrl/api/$($spaceId)/interruptions/$($manualIntervention.Id)/responsible\" -Headers $header\n\n # Create response object\n $jsonBody = @{\n Notes = $automaticResponseReasonNotes\n }\n\n # Check to see if manual intervention is empty\n if (![string]::IsNullOrWhiteSpace($automaticResponseManualInterventionResponseType))\n {\n # Add the manual intervention type\n Write-Host \"Submitting $automaticResponseManualInterventionResponseType as response ...\"\n $jsonBody.Add(\"Result\", $automaticResponseManualInterventionResponseType)\n }\n\n # Check to see if the guided failure is empty\n if (![string]::IsNullOrWhiteSpace($automaticResponseGuidedFailureResponseType))\n {\n # Add the guided failure response\n Write-Host \"Submitting $automaticResponseGuidedFailureResponseType as response ...\"\n $jsonBody.Add(\"Guidance\", $automaticResponseGuidedFailureResponseType)\n }\n\n # Post to server\n Invoke-RestMethod -Method Post -Uri \"$automaticResponseOctopusUrl/api/$($spaceId)/interruptions/$($manualIntervention.Id)/submit\" -Body ($jsonBody | ConvertTo-Json -Depth 10) -Headers $header\n }\n }\n}"
},
"Parameters": [
{
Expand Down Expand Up @@ -66,10 +66,10 @@
}
],
"$Meta": {
"ExportedAt": "2021-10-01T17:52:01.610Z",
"OctopusVersion": "2021.2.7580",
"ExportedAt": "2025-04-21T20:17:19.315Z",
"OctopusVersion": "2025.2.7176",
"Type": "ActionTemplate"
},
"LastModifiedBy": "twerthi",
"Category": "octopus"
}
}