Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Azure Automation runbook在从Webhook触发时失败_Azure_Powershell_Azure Automation - Fatal编程技术网

Azure Automation runbook在从Webhook触发时失败

Azure Automation runbook在从Webhook触发时失败,azure,powershell,azure-automation,Azure,Powershell,Azure Automation,Azure Automation runbook在从Webhook触发时失败 我们有一个运行手册,通过Azure门户中的“开始”按钮启动时运行良好 当使用完全相同的参数从webhook启动时,完全相同的runbook会失败 问题是,在runbook中的代码打开到Azure的有效连接后,它尝试获取我们将要使用的其中一个数据库,但失败,出现了一个异常,即“找不到资源组” 在Webhook之外运行时,相同的代码和参数不会出现任何问题 我们在代码登录后添加了获取上下文的代码,并检查了上下文名称、订阅ID

Azure Automation runbook在从Webhook触发时失败 我们有一个运行手册,通过Azure门户中的“开始”按钮启动时运行良好

当使用完全相同的参数从webhook启动时,完全相同的runbook会失败

问题是,在runbook中的代码打开到Azure的有效连接后,它尝试获取我们将要使用的其中一个数据库,但失败,出现了一个异常,即“找不到资源组”

在Webhook之外运行时,相同的代码和参数不会出现任何问题

我们在代码登录后添加了获取上下文的代码,并检查了上下文名称、订阅ID和租户ID是否有效,我们甚至将上下文传递给get-AzSqlDatabase调用,但在通过webhook触发时仍然失败。我们不确定还可以尝试什么来诊断和纠正该问题

下面是我们运行的代码示例以及失败的地方

. . .
Function Login {
    Disable-AzContextAutosave -Scope Process

    Write-Output "Logging in to Azure..."
    $connectionName = "GoodTestingConnection"    
    try{
            Connect-AzAccount -ServicePrincipal -Tenant $servicePrincipalConnection.TenantId `
            -ApplicationId $servicePrincipalConnection.ApplicationId `
            -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint
        }
        catch {
            Write-Output "Error loging in to Azure: $_"
            throw "Error loging in to Azure: $_"
        }        
}

$ErrorActionPreference = "Stop"

if ($WebHookData) {
    Write-Output "Running runbook from web hook request"
    $wbRunParams = (ConvertFrom-Json -InputObject $WebHookData.RequestBody)
    Write-Output "Webhook parameters $wbRunParams"
    $client = $wbRunParams.client

    Write-Output "Running process for client $client"        
}

Login

$ctx = Get-AzContext
Write-Output "Context nanme: $($ctx.Name)"
Write-Output "Environment name: $($ctx.Environment.Name)"
Write-Output "Subscription ID: $($ctx.Subscription.Id)"
Write-Output "Tenant ID: $($ctx.Tenant.Id)"

Write-Output "Getting the 'from' Db..."
$fromDb = Get-AzSqlDatabase `
                -DatabaseName $copyFromDbName `
                -ServerName $copyFromServer `
                -ResourceGroupName $copyFromRG `
                -DefaultProfile $ctx
    $fromDb

#The code never reaches this point as it fails on the previous call
. . .

我也有同样的问题。这是对我有用的东西

当通过开始选项或测试窗格触发自动化runbook时,需要转换格式。这是您将使用

$wbRunParams = (ConvertFrom-Json -InputObject $WebHookData.RequestBody)
当runbook必须由webhook直接触发时,不需要转换,下面的操作也可以

$wbRunParams = $WebHookData.RequestBody

我也有同样的问题。这是对我有用的东西

当通过开始选项或测试窗格触发自动化runbook时,需要转换格式。这是您将使用

$wbRunParams = (ConvertFrom-Json -InputObject $WebHookData.RequestBody)
当runbook必须由webhook直接触发时,不需要转换,下面的操作也可以

$wbRunParams = $WebHookData.RequestBody