- "Octopus.Action.Script.ScriptBody": "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12\n\n# Helper functions\nfunction Retry-Command {\n [CmdletBinding()]\n Param(\n [Parameter(Position=0, Mandatory=$true)]\n [scriptblock]$ScriptBlock,\n \n [Parameter(Position=1, Mandatory=$false)]\n [int]$Maximum = 5,\n\n [Parameter(Position=2, Mandatory=$false)]\n [int]$Delay = 100\n )\n\n Begin {\n $count = 0\n }\n\n Process {\n \t$ex=$null\n do {\n $count++\n \n try {\n Write-Verbose \"Attempt $count of $Maximum\"\n $ScriptBlock.Invoke()\n return\n } catch {\n $ex = $_\n Write-Warning \"Error occurred executing command (on attempt $count of $Maximum): $($ex.Exception.Message)\"\n Start-Sleep -Milliseconds $Delay\n }\n } while ($count -lt $Maximum)\n\n throw \"Execution failed (after $count attempts): $($ex.Exception.Message)\"\n }\n}\n# End Helper functions\n\n[int]$timeoutSec = $null\n[int]$maximum = 1\n[int]$delay = 100\n\nif(-not [int]::TryParse($OctopusParameters['Timeout'], [ref]$timeoutSec)) { $timeoutSec = 60 }\n\nif ($OctopusParameters[\"AutomatePostMessage.RetryPosting\"] -eq $True) {\n\tif(-not [int]::TryParse($OctopusParameters['RetryCount'], [ref]$maximum)) { $maximum = 1 }\n\tif(-not [int]::TryParse($OctopusParameters['RetryDelay'], [ref]$delay)) { $delay = 100 }\n\t\n Write-Verbose \"Setting maximum retries to $maximum using a $delay ms delay\"\n}\n\n# Create the payload for Power Automate\n$payload = @{\n type = \"message\" # Fixed value for message type\n attachments = @(\n @{\n contentType = \"application/vnd.microsoft.card.adaptive\"\n content = @{\n type = \"AdaptiveCard\"\n body = @(\n @{\n type = \"TextBlock\"\n text = $OctopusParameters['Title']\n weight = \"bolder\"\n size = \"medium\"\n color= $OctopusParameters['TitleColor']\n },\n @{\n type = \"TextBlock\"\n text = $OctopusParameters['Body']\n wrap = $true\n color= $OctopusParameters['BodyColor']\n }\n )\n actions = @(\n @{\n type = \"Action.OpenUrl\"\n title = $OctopusParameters['ButtonTitle']\n url = $OctopusParameters['ButtonUrl']\n }\n )\n \"`$schema\" = \"http://adaptivecards.io/schemas/adaptive-card.json\"\n version = \"1.0\"\n }\n }\n )\n}\n\nRetry-Command -Maximum $maximum -Delay $delay -ScriptBlock {\n #Write-Output ($payload | ConvertTo-Json -Depth 6)\n \n # Prepare parameters for the POST request\n $invokeParameters = @{\n Method = \"POST\"\n Uri = $OctopusParameters['HookUrl']\n Body = ($payload | ConvertTo-Json -Depth 6 -Compress)\n ContentType = \"application/json; charset=utf-8\"\n TimeoutSec = $timeoutSec\n }\n\n # Check for UseBasicParsing (needed for some environments)\n if ((Get-Command Invoke-RestMethod).Parameters.ContainsKey(\"UseBasicParsing\")) {\n $invokeParameters.Add(\"UseBasicParsing\", $true)\n }\n\n # Send the request to the Power Automate webhook\n $Response = Invoke-RestMethod @invokeParameters\n Write-Verbose \"Response: $Response\"\n}\n",
0 commit comments