我正在尝试使用Azure DevOps任务以编程方式将LUIS预测资源分配给LUIS应用程序,如此处所述。简而言之,这涉及
我可以手动执行这些步骤,但是如何从Azure DevOps执行此操作?我试图从无代理作业中使用“调用REST API”任务,但是看不到如何检索和使用Bearer令牌。请注意,承载令牌已过期。
谢谢你的建议。
您可以在管道中添加一个powershell任务,以通过azure devops执行此操作。
获取Azure资源管理器令牌:可以参考下面的Powershell脚本来获取令牌。请点击这里了解哪里可以获取客户端ID和客户端密钥的更多信息。请注意,此处的资源为“ https://management.core.windows.net/ ”
$client_id = "{client id}"
$client_secret = "{client secret}"
$uri= "https://login.microsoftonline.com/{tenant id}/oauth2/token"
$Body = @{
'resource'= "https://management.core.windows.net/"
'client_id' = $client_id
'grant_type' = 'client_credentials'
'client_secret' = $client_secret
}
$params = @{
ContentType = 'application/x-www-form-urlencoded'
Headers = @{'accept'='application/json'}
Body = $Body
Method = 'Post'
URI = $uri
}
$response = Invoke-RestMethod @params
$token = $response.access_token
获得令牌后,可以将其传递给LUIS rest api。下面的脚本仅作为示例。
$LuisBody = @{
"azureSubscriptionId"= "{subscription_id}"
"resourceGroup"= "{resource_group_name}"
"accountName"= "{account_name}"
}
$Luisparams = @{
Headers = @{
Authorization = ("Bearer {0}" -f $token) # pass the token which got from above script
"Ocp-Apim-Subscription-Key" = "{subscription key}"
ContentType = "application/json"
}
Body = $LuisBody
Method = 'Post'
URI = "https://{endpoint}/luis/api/v2.0/apps/{appId}/azureaccounts"
}
Invoke-RestMethod @Luisparams
还有另一个博客可能对您有所帮助。
更新:带有以下脚本的带有Azure CLI的GetAzure资源管理器令牌:
az account get-access-token --resource=https://management.core.windows.net/ | jq -r .accessToken
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句