diff --git a/gulpfile.babel.js b/gulpfile.babel.js index 31d5ac99..114233eb 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -203,6 +203,8 @@ function humanize(categoryId) { return "MariaDB"; case "microsoft-teams": return "Microsoft Teams"; + case "microsoft-power-automate": + return "Microsoft Power Automate"; case "mongodb": return "MongoDB"; case "mulesoft": diff --git a/step-templates/logos/microsoft-power-automate.png b/step-templates/logos/microsoft-power-automate.png new file mode 100644 index 00000000..6b8c1ed1 Binary files /dev/null and b/step-templates/logos/microsoft-power-automate.png differ diff --git a/step-templates/microsoft-power-automate-post-adaptivecard.json b/step-templates/microsoft-power-automate-post-adaptivecard.json new file mode 100644 index 00000000..2c2fe789 --- /dev/null +++ b/step-templates/microsoft-power-automate-post-adaptivecard.json @@ -0,0 +1,136 @@ +{ + "Id": "707e6dae-0d6f-4121-ab8d-6961039c4162", + "Name": "Microsoft Power Automate - Post AdaptiveCard", + "Description": "Posts a message to Microsoft Teams using Microsoft Power Automate webhook.", + "ActionType": "Octopus.Script", + "Version": 1, + "CommunityActionTemplateId": null, + "Packages": [], + "GitDependencies": [], + "Properties": { + "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", + "Octopus.Action.Script.Syntax": "PowerShell", + "Octopus.Action.Script.ScriptSource": "Inline" + }, + "Parameters": [ + { + "Id": "5d460a15-4052-44f7-85a2-f75cdf77da03", + "Name": "PowerAutomatePostAdaptiveCard.HookUrl", + "Label": "Webhook Url", + "HelpText": "The specific URL created by Microsoft Power Automate using 'When a Teams webhook request is received' flow template. Copy and paste the full HTTP URL from Microsoft Power Automate.", + "DefaultValue": "", + "DisplaySettings": { + "Octopus.ControlType": "SingleLineText" + } + }, + { + "Id": "53b1de0d-261e-464f-91e1-b7307fd5d1a2", + "Name": "PowerAutomatePostAdaptiveCard.Title", + "Label": "Message title", + "HelpText": "The title of the message that will be posted to your Microsoft Teams channel.", + "DefaultValue": "#{Octopus.Project.Name} #{Octopus.Release.Number} deployed to #{Octopus.Environment.Name}#{if Octopus.Deployment.Tenant.Id} for #{Octopus.Deployment.Tenant.Name}#{/if}", + "DisplaySettings": { + "Octopus.ControlType": "SingleLineText" + } + }, + { + "Id": "14c34ec8-5e44-40c6-bf93-7d4920a78b80", + "Name": "PowerAutomatePostAdaptiveCard.Body", + "Label": "Message body", + "HelpText": "The message body of post being added to your Microsoft Teams channel.", + "DefaultValue": "For more information, please see [deployment details](#{if Octopus.Web.ServerUri}#{Octopus.Web.ServerUri}#{else}#{Octopus.Web.BaseUrl}#{/if}#{Octopus.Web.DeploymentLink})!", + "DisplaySettings": { + "Octopus.ControlType": "MultiLineText" + } + }, + { + "Id": "60d65627-fa61-4203-becf-ae316488a774", + "Name": "PowerAutomatePostAdaptiveCard.TitleColor", + "Label": "Title Color", + "HelpText": "The color to use for the title of the adaptive card.", + "DefaultValue": "default", + "DisplaySettings": { + "Octopus.ControlType": "Select", + "Octopus.SelectOptions": "default|Default\ndark|Dark\nlight|Light\naccent|Accent\ngood|Good\nwarning|Warning\nattention|Attention" + } + }, + { + "Id": "1491e7d2-2677-4119-a159-09715173af25", + "Name": "PowerAutomatePostAdaptiveCard.Timeout", + "Label": "Timeout in seconds", + "HelpText": "The maximum timeout in seconds for each request.", + "DefaultValue": "60", + "DisplaySettings": { + "Octopus.ControlType": "SingleLineText" + } + }, + { + "Id": "0c5e5a4a-35c2-48f7-b0e3-6e2e2b14b383", + "Name": "PowerAutomatePostAdaptiveCard.RetryPosting", + "Label": "Retry posting message", + "HelpText": "Should retries be made? If this option is enabled, the step will attempt to retry the posting of message to teams up to the set retry count. Default: `False`.", + "DefaultValue": "False", + "DisplaySettings": { + "Octopus.ControlType": "Checkbox" + } + }, + { + "Id": "b1d2acda-5e82-42a9-bd05-6cc4827f5974", + "Name": "PowerAutomatePostAdaptiveCard.RetryCount", + "Label": "Retry Count", + "HelpText": "The maximum number of times to retry the post before allowing failure. Default 1", + "DefaultValue": "1", + "DisplaySettings": { + "Octopus.ControlType": "SingleLineText" + } + }, + { + "Id": "bc9438f7-3c74-4f2e-a5a5-4cb4c38767d9", + "Name": "PowerAutomatePostAdaptiveCard.RetryDelay", + "Label": "Retry delay in milliseconds", + "HelpText": "The amount of time in milliseconds to wait between retries. Default 100", + "DefaultValue": "100", + "DisplaySettings": { + "Octopus.ControlType": "SingleLineText" + } + }, + { + "Id": "e1606576-d9af-489f-a343-916cc809c1c3", + "Name": "PowerAutomatePostAdaptiveCard.BodyColor", + "Label": "Body Color", + "HelpText": "The color to use for the body of the adaptive card.", + "DefaultValue": "default", + "DisplaySettings": { + "Octopus.ControlType": "Select", + "Octopus.SelectOptions": "default|Default\ndark|Dark\nlight|Light\naccent|Accent\ngood|Good\nwarning|Warning\nattention|Attention" + } + }, + { + "Id": "6222bf83-af8b-40dd-a504-eb7ab0208981", + "Name": "PowerAutomatePostAdaptiveCard.ButtonTitle", + "Label": "Button Title", + "HelpText": "The button title of post being added to your Microsoft Teams channel.", + "DefaultValue": "Adaptive Card Designer", + "DisplaySettings": { + "Octopus.ControlType": "SingleLineText" + } + }, + { + "Id": "a550bde0-e622-457c-b2b6-6a6089cf2fa8", + "Name": "PowerAutomatePostAdaptiveCard.ButtonUrl", + "Label": "Button url", + "HelpText": "The button url of post being added to your Microsoft Teams channel.", + "DefaultValue": "https://adaptivecards.io/designer/", + "DisplaySettings": { + "Octopus.ControlType": "SingleLineText" + } + } + ], + "$Meta": { + "ExportedAt": "2024-11-13T22:40:25.875Z", + "OctopusVersion": "2024.3.12828", + "Type": "ActionTemplate" + }, + "LastModifiedBy": "Zunair", + "Category": "microsoft-power-automate" +}