Skip to content

Commit caadef5

Browse files
authored
Merge pull request #1602 from OctopusDeploy/update-automate-response
Fixing template
2 parents 70ebd00 + 96940cb commit caadef5

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

step-templates/automate-manual-intervention-response.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
"Name": "Automate Manual Intervention Response",
44
"Description": "This template will search for deployments that have been paused due to Manual Intervention or Guided Failure and automate the response.",
55
"ActionType": "Octopus.Script",
6-
"Version": 2,
6+
"Version": 3,
77
"CommunityActionTemplateId": null,
88
"Packages": [],
99
"Properties": {
1010
"Octopus.Action.Script.ScriptSource": "Inline",
1111
"Octopus.Action.Script.Syntax": "PowerShell",
12-
"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}"
12+
"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}"
1313
},
1414
"Parameters": [
1515
{
@@ -66,10 +66,10 @@
6666
}
6767
],
6868
"$Meta": {
69-
"ExportedAt": "2021-10-01T17:52:01.610Z",
70-
"OctopusVersion": "2021.2.7580",
69+
"ExportedAt": "2025-04-21T20:17:19.315Z",
70+
"OctopusVersion": "2025.2.7176",
7171
"Type": "ActionTemplate"
7272
},
7373
"LastModifiedBy": "twerthi",
7474
"Category": "octopus"
75-
}
75+
}

0 commit comments

Comments
 (0)