Skip to content

Commit f5c60ca

Browse files
authored
Merge pull request #1595 from benjimac93/master
Update microsoft-power-automate-post-adaptivecard to match variables used in step
2 parents c5c1a7d + b4bb4df commit f5c60ca

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

step-templates/microsoft-power-automate-post-adaptivecard.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
"Name": "Microsoft Power Automate - Post AdaptiveCard",
44
"Description": "Posts a message to Microsoft Teams using Microsoft Power Automate webhook.",
55
"ActionType": "Octopus.Script",
6-
"Version": 1,
6+
"Version": 2,
77
"CommunityActionTemplateId": null,
88
"Packages": [],
99
"GitDependencies": [],
1010
"Properties": {
11-
"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",
11+
"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['PowerAutomatePostAdaptiveCard.Timeout'], [ref]$timeoutSec)) { $timeoutSec = 60 }\n\nif ($OctopusParameters[\"AutomatePostMessage.RetryPosting\"] -eq $True) {\n\tif(-not [int]::TryParse($OctopusParameters['PowerAutomatePostAdaptiveCard.RetryCount'], [ref]$maximum)) { $maximum = 1 }\n\tif(-not [int]::TryParse($OctopusParameters['PowerAutomatePostAdaptiveCard.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['PowerAutomatePostAdaptiveCard.Title']\n weight = \"bolder\"\n size = \"medium\"\n color= $OctopusParameters['PowerAutomatePostAdaptiveCard.TitleColor']\n },\n @{\n type = \"TextBlock\"\n text = $OctopusParameters['PowerAutomatePostAdaptiveCard.Body']\n wrap = $true\n color= $OctopusParameters['PowerAutomatePostAdaptiveCard.BodyColor']\n }\n )\n actions = @(\n @{\n type = \"Action.OpenUrl\"\n title = $OctopusParameters['PowerAutomatePostAdaptiveCard.ButtonTitle']\n url = $OctopusParameters['PowerAutomatePostAdaptiveCard.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['PowerAutomatePostAdaptiveCard.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(\"PowerAutomatePostAdaptiveCard.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",
1212
"Octopus.Action.Script.Syntax": "PowerShell",
1313
"Octopus.Action.Script.ScriptSource": "Inline"
1414
},
@@ -126,11 +126,12 @@
126126
}
127127
}
128128
],
129+
"StepPackageId": "Octopus.Script",
129130
"$Meta": {
130-
"ExportedAt": "2024-11-13T22:40:25.875Z",
131-
"OctopusVersion": "2024.3.12828",
131+
"ExportedAt": "2025-03-10T22:22:38.638Z",
132+
"OctopusVersion": "2025.2.1265",
132133
"Type": "ActionTemplate"
133134
},
134-
"LastModifiedBy": "Zunair",
135+
"LastModifiedBy": "benjimac93",
135136
"Category": "microsoft-power-automate"
136137
}

0 commit comments

Comments
 (0)