通过DevOps Pipeline在Azure中的功能APP上检查功能

发布于 2025-02-13 12:48:56 字数 340 浏览 0 评论 0原文

在Azure DevOps上,我有一个构建/部署YAML管道,该管道可以构建我的功能应用程序,并将其部署到Azure的Linux函数应用程序(在App-Service计划中托管)。

但是,最近我注意到了一个问题,该管道显示了该函数应用程序已成功部署,但是在Azure中进入功能应用并单击左侧的“功能”选项卡时,它显示了“无结果”,但是应该有4个函数在那里。

我想在部署管道的末尾有一个步骤,该步骤检查该功能应用中是否存在4个函数,并且如果不是这种情况,则在管道上运行。

我知道这很可能是使用Azure CLI或PowerShell的管道中的一项任务,但是不确定我将如何编写脚本。任何帮助将不胜感激。

谢谢大家,

On Azure DevOps I have a build/deploy YAML pipeline which builds my Function App and deploys this to a Linux Function App in Azure (hosted on an app-service plan).

However, recently I noticed an issue where the pipeline was showing the function app was successfully deployed, but when going into the FunctionApp in Azure and clicking on the Functions tab on the left, it shows "No results", but there should be 4 functions in there.

I want to have a step at the end of the deploy pipeline which checks that 4 functions exist in this FunctionApp, and to fail the pipeline run if this is not the case.

I know this will most likely be a task in the pipeline using Azure CLI or Powershell, but not sure how I would go around writing the script. Any help would be immensely appreciated.

Thanks all,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清引 2025-02-20 12:48:56

您可以使用Azure CLI任务,并致电REST API使用功能应用列出功能。我认为本地AZ CLI和Azure PowerShell函数不会在功能应用中揭示功能/

URI = "https://management.azure.com/subscriptions/<subscriptionId>/resourceGroups/<resourceGroupName>/providers/Microsoft.Web/sites/<functionAppName>/functions?api-version=2015-08-01"

az rest -u $URI --method get | jq '.value[].name'

You could use an Azure CLI task and call the Rest API to list the functions withint the FunctionApp. I don't think the native Az CLI and Azure PowerShell functions expose the functions within the FunctionApp/

URI = "https://management.azure.com/subscriptions/<subscriptionId>/resourceGroups/<resourceGroupName>/providers/Microsoft.Web/sites/<functionAppName>/functions?api-version=2015-08-01"

az rest -u $URI --method get | jq '.value[].name'

淤浪 2025-02-20 12:48:56
steps:
- powershell: |
   #get token
   $TENANTID="xxx"
   $APPID="xxx"
   $PASSWORD="xxx"
   $result=Invoke-RestMethod -Uri https://login.microsoftonline.com/$TENANTID/oauth2/token?api-version=1.0 -Method Post -Body @{"grant_type" = "client_credentials"; "resource" = "https://management.core.windows.net/"; "client_id" = "$APPID"; "client_secret" = "$PASSWORD" }
   $token=$result.access_token
   
   ##set Header
   $Headers=@{
       'authorization'="Bearer $token"
       'host'="management.azure.com"
   }
   
   $functions = Invoke-RestMethod  -Uri "https://management.azure.com/subscriptions/<subcription id>/resourceGroups/<resource group name>/providers/Microsoft.Web/sites/<function app name>/functions?api-version=2015-08-01"  -Headers $Headers -ContentType "application/json" -Method GET
   
   
   if($functions.value.Count -eq 4) {
       # make pipeline to succeed
       Write-Host 'Function deployment success.'
       exit 0
   }
   else {
       Write-Host 'Function deployment failed.'
       exit 1
   }
   
   
  displayName: 'Check whether the function app deployment completed.'

如果您有担忧,请告诉我。

steps:
- powershell: |
   #get token
   $TENANTID="xxx"
   $APPID="xxx"
   $PASSWORD="xxx"
   $result=Invoke-RestMethod -Uri https://login.microsoftonline.com/$TENANTID/oauth2/token?api-version=1.0 -Method Post -Body @{"grant_type" = "client_credentials"; "resource" = "https://management.core.windows.net/"; "client_id" = "$APPID"; "client_secret" = "$PASSWORD" }
   $token=$result.access_token
   
   ##set Header
   $Headers=@{
       'authorization'="Bearer $token"
       'host'="management.azure.com"
   }
   
   $functions = Invoke-RestMethod  -Uri "https://management.azure.com/subscriptions/<subcription id>/resourceGroups/<resource group name>/providers/Microsoft.Web/sites/<function app name>/functions?api-version=2015-08-01"  -Headers $Headers -ContentType "application/json" -Method GET
   
   
   if($functions.value.Count -eq 4) {
       # make pipeline to succeed
       Write-Host 'Function deployment success.'
       exit 0
   }
   else {
       Write-Host 'Function deployment failed.'
       exit 1
   }
   
   
  displayName: 'Check whether the function app deployment completed.'

If you have concerns, let me know.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文