【发布时间】:2021-05-27 09:53:46
【问题描述】:
我想通过 Azure DevOps 管道为容器上的 Azure WebApp 更新配置一个带有 Azure 文件共享(路径映射)的 Azure 存储装载。为此,我目前正在使用“Azure PowerShell 任务”(下面的代码)。但是,PowerShell 脚本正在配置“高级”选项,并公开存储帐户访问密钥。有没有办法配置“基本”。
PowerShell“New-AzWebAppAzureStoragePath”创建一个“高级”配置。
还有一个 Devops 任务“Azure webapp for containers”允许我设置“应用设置”和“配置设置”,但没有“路径映射”选项。
在 PowerShell 或 Azure devops 任务中是否有任何替代方法,以使用“BASIC”配置创建到 Azure 文件共享的“路径映射”。
脚本:
try{
# Check if AzureStoragePath (PATH MAPPINGS) already exists for the web app
$webapp = get-AzWebApp -ResourceGroupName $webAppResourceGroupName -Name $webAppName
if($webapp.AzureStoragePath -ne $null){
# 'Path Mapping' to Azure storage File does not exist. Proceed with creating one.
# Get Storage Account Primary Key
$storageAccountKey = (Get-AzStorageAccountKey -ResourceGroupName $storageResourceGroupName -AccountName $storageAccountName).value[0]
$storageAccountContext = New-AzStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey
# Returns 'True' or 'False' depending whether File share exists or not
$storageShareObject = get-azstorageshare -Name $storageFileShareName -context $storageAccountContext -erroraction silentlycontinue
$storageShareExists = (($storageShareObject) -ne $null)
if($storageShareExists -ne 'True'){
$storageShareObjectFQDN = $storageShareObject.name + ".files.core.windows.net"
# Create a WebApp Storage Path object
$webAppStoragePathObject = New-AzWebAppAzureStoragePath -Name 'someConfig' -AccountName $storageShareObjectFQDN -Type AzureFiles -ShareName $storageFileShareName -AccessKey $storageAccountKey -MountPath "/edgemicro/config"
# Configure the 'Path mappings' for the web app
Set-AzWebApp -ResourceGroupName $webAppResourceGroupName -Name $webAppName -AzureStoragePath $webAppStoragePathObject
}
}
}catch{
# '$_' contains all the details about exception
$_
}
【问题讨论】:
-
嗨,您有机会查看以下答案吗?如果它帮助您解决此问题,请告诉我
标签: azure-devops azure-web-app-service azure-storage azure-powershell