You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Bicep获取App Service/Function的发布配置文件或发布密码?

纯Bicep获取App Service/Function发布配置文件或密码的解决方案

问题场景

使用Bicep尝试获取App Service或Function的发布配置文件时,原代码返回空字符串,已拥有Microsoft.Web/sites/config/list/Action和Microsoft.Web/sites/publishxml/Action权限,需要纯Bicep实现获取发布配置XML或至少发布密码(已知Azure CLI可实现,但需Bicep方案)。

原无效代码:

param appserviceOrFunctionName string
 
var publishingCredentialsId = resourceId('Microsoft.Web/sites/config', appserviceOrFunctionName, 'publishingCredentials')
 
# disable-next-line outputs-should-not-contain-secrets
output publish_profile object = list(publishingCredentialsId, '2022-03-01')

原因分析

原代码针对Microsoft.Web/sites/config/publishingCredentials资源调用list操作,该路径的list动作无法返回有效发布凭证,正确的做法是直接针对Microsoft.Web/sites资源调用对应的专用动作。

解决方法

1. 获取发布密码(非XML格式)

通过调用listPublishingCredentials动作获取包含密码的凭证信息:

param appserviceOrFunctionName string
param resourceGroupName string

# 构建网站资源ID
var siteResourceId = resourceId(resourceGroupName, 'Microsoft.Web/sites', appserviceOrFunctionName)

# 获取发布密码
# disable-next-line outputs-should-not-contain-secrets
output publishingPassword string = list(siteResourceId, '2022-03-01', 'listPublishingCredentials').properties.publishingPassword

2. 获取完整发布配置XML

通过调用publishxml动作直接获取XML格式的发布配置文件:

param appserviceOrFunctionName string
param resourceGroupName string

# 构建网站资源ID
var siteResourceId = resourceId(resourceGroupName, 'Microsoft.Web/sites', appserviceOrFunctionName)

# 获取发布配置XML字符串
# disable-next-line outputs-should-not-contain-secrets
output publishProfileXml string = list(siteResourceId, '2022-03-01', 'publishxml').publishProfile

权限要求

确保执行Bicep部署的身份拥有以下权限:

  • Microsoft.Web/sites/listPublishingCredentials/Action(用于获取密码)
  • Microsoft.Web/sites/publishxml/Action(用于获取XML配置)

内容的提问来源于stack exchange,提问作者Adam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 10:43:16