簡體   English   中英

從 ADF Webhook 活動調用 Azure Automation Runbook - 失敗並顯示“無法將參數綁定到參數‘InputObject’,因為它是 null。”

[英]Calling Azure Automation runbook from ADF Webhook activity - Fails with "Cannot bind argument to parameter 'InputObject' because it is null."

我們正在嘗試從 Azure 數據工廠管道中的 Webhook 活動調用 Azure Automation Runbook。

我們按照這篇博文中提供的說明進行工作: https://medium.com/hitachisolutions-braintrust/3-steps-to-run-powershell-in-azure-data-factory-e7c73d38e548

涉及兩個組件:

  1. Azure 自動化操作手冊,包含 PowerShell 腳本
  2. ADF 管道 webhook 活動,調用 Automation Runbook

目的是讀取 PS 腳本的輸入參數 (WebhookData) 中包含的屬性 (RequestBody),它表示 json 格式的字符串。

為了清楚起見,我已經剝離了盡可能多的代碼(實際腳本包含更多行)。 例如,我刪除了對回調等的任何引用...因為(此時)這不是我們面臨的問題的一部分。

此外,我還描述了 2 個連續版本的 Automation Runbook,以演示到目前為止我們是如何嘗試解決錯誤的。

自動化操作手冊(初始版本)

運行手冊的 PowerShell 代碼:

param (
[Parameter (Mandatory = $false)]
[object] $WebHookData
)

$Parameters = (ConvertTo-Json -InputObject $WebhookData.RequestBody) // This line fails

網絡鈎子活動

json 調用自動化 runbook 的 webhook 活動的定義:

{
"name": "Automation Runbook Test",
"properties": {
    "description": "Performs a simple test to call a runbook from within ADF",
    "activities": [
        {
            "name": "WebHook1",
            "type": "WebHook",
            "dependsOn": [],
            "userProperties": [],
            "typeProperties": {
                "url": "https://xxxxxxxx-94be-4cb8-9ba7-b50d7de44a82.webhook.we.azure-automation.net/webhooks?token=xxxxxxxxxx6bjpZH36io1mhP%2b5k2yr%2bMcVvsYGjdZPE%3d",
                "method": "POST",
                "headers": {
                    "Content-Type": "application/json"
                },
                "body": {
                    "ParmMsg": "I am completely operational, and all my circuits are functioning perfectly."
                },
                "timeout": "00:00:30"
            }
        }
    ],
    "folder": {
        "name": "Refresh Power BI"
    },
    "annotations": []
},
"type": "Microsoft.DataFactory/factories/pipelines"
}

執行錯誤

執行自動化 Runbook 失敗並出現以下錯誤:無法將參數綁定到參數“InputObject”,因為它是 null。

自動化操作手冊(第二版)

為了了解發生了什么,我們嘗試了幾種方法。 我們注意到將 WebhookData 參數轉換為 PSCustomObject 似乎讓我們更近了一步,但是當我們嘗試繼續前進時,我們遇到了下一個問題。 這就是我們目前所處的困境。

這是新版本:

param (
[Parameter (Mandatory = $false)]
[object] $WebHookData
)

# Convert WebhookData parameter (json-formatted string) to an Automation.PSCustomObject object
$WebHookData = (ConvertFrom-Json -InputObject $WebhookData)
Write-Output "WebhookData.RequestBody"
Write-Output "-----------------------"
Write-Output $WebhookData.RequestBody

# Get all parameters from body 
# (passed from Data Factory Web Activity)
$Parameters = (ConvertFrom-Json -InputObject $WebhookData.RequestBody) // This line fails

Write-Output "Parameters"
Write-Output "----------"
Write-Output $Parameters

Output & 錯誤(來自第二版)

$WebhookData.RequestBody 的 Write-Output 顯示轉義字符 (\r\n) 已添加到 RequestBody 屬性,與在 ADF webhook 活動設置中輸入的原始 json 相比(見上文):

WebhookData.RequestBody
-----------------------
{\r\n "ParmMsg": "I am completely operational, and all my circuits are functioning perfectly.",\r\n "callBackUri": "https://dpwesteurope.svc.datafactory.azure.com/dataplane/workflow/callback/....

該腳本現在失敗了
從 JSON 轉換失敗,出現錯誤:無效的屬性標識符 | 特點: 。 路徑 '',第 1 行,position 1。

當(手動)刪除轉義字符時,腳本運行正常。 但是,這些轉義字符是由 ADF Webhook 活動放置在那里的,似乎沒有辦法控制它。 我認為也不應該在那里改變它。 相反,自動化 runbook 腳本可能應該被更改,以便它將 RequestBody 屬性(外部 WebhookData 對象的)識別為有效的 json,它可以將其轉換為 PSCustomObject。 如圖所示,我們的腳本此時顯然無法做到這一點。

任何建議都非常受歡迎。

謝謝!

自原始帖子更新

我將 Runbook 的運行時版本從 7.1(預覽版)更改為 5.1。 在 5.1 版本中,腳本似乎可以正確運行。 那么,是 7.1 版本的原因,還是我在這里遺漏了其他東西?

事實證明,Powershell 7.1(預覽版)目前存在一個已知問題

使用 webhook 啟動 PowerShell 7 runbook 時,它會自動將 webhook 輸入參數轉換為無效的 JSON。

來源: https://learn.microsoft.com/en-us/azure/automation/automation-runbook-types#known-issues---71-preview

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM