【问题标题】:How do I deploy to Azure App Service with PowerShell?如何使用 PowerShell 部署到 Azure 应用服务?
【发布时间】:2017-08-23 21:59:02
【问题描述】:

我环顾四周,使用 PowerShell 中的 Azure 和 AzureRM commandlet 中的数千个命令,我仍然不确定如何执行此操作。

到目前为止我的工作:

  • 安装 Azure 和 AzureRM 模块并将它们导入脚本
  • 从 get-AzurePublishSettingsFile 命令生成“*.publishsettings”文件
  • 导入了“*.publishsettings”文件
  • 可以使用“Stop-AzureWebsite”和“Start-AzureWebsite”命令行开关访问网站

我需要做的:

  • 创建新部署并将文件推送到应用服务站点。

注意:我没有 Visual Studio 项目和 .csproj 文件配置。我只是想获取一个文件夹的内容并将其推送到网站。

任何帮助都会很有用,因为文档在细节方面确实很糟糕,而且 PowerShell 中有数千个命令需要执行。

【问题讨论】:

  • 您是否希望将您的网站作为 Web 部署包部署到 Azure 应用服务站点?
  • @juvchan :它基本上只是一堆文件(主要是 *.js、*.css 和 *.html),而不是一个包。如果需要,我可以压缩它们,但它们不是 VS 项目或其他项目的一部分。
  • 如果您知道如何使用 msdeploy 命令将您的网站文件打包到 Web Deploy 包中,这些步骤将很简单,如果您觉得此解决方案可行,我将能够从那里指导您
  • @juvchan :得到这个与沃尔特的答案一起工作,但感谢您的帮助!

标签: powershell azure azure-web-app-service


【解决方案1】:

您可以查看blog:Deploy an App Service using Azure PowerShell to a Deployment Slot

Get-AzurePublishSettingsFile
Import-AzurePublishSettingsFile .\Your-Publish-Settings-credentials.publishsettings
Get-AzureSubscription
Select-AzureSubscription -SubscriptionName "The Subscription Name containing the slot"
Set-AzureSubscription -SubscriptionId "ID of subscription"

$WebAppName = "standard(staging)"
Get-AzureWebsite -Name $WebAppName
Publish-AzureWebsiteProject -Name $WebAppName -Package "C:\PowerShell\standard.zip" -Slot "staging"

【讨论】:

  • 所以我可以使用“Publish-AzureWebsiteProject”并将其作为包传递一个 zip 文件吗?我看到的所有文档都提到了“*.csporj”包。
  • 刚刚回来确认这适用于 zip 文件。终于解决了这个问题。感谢您的帮助
【解决方案2】:

【讨论】:

  • 在 Stackoverflow 中说“上述链接”没有意义。该页面将在每次刷新时随机播放答案。
  • 仍在学习中。我已经包含了我正在谈论的链接。谢谢指正。
  • @Jay 这将是我的备份解决方案。感谢您的信息,但我得到了它与沃尔特斯的答案一起使用。
【解决方案3】:

不幸的是,接受的答案给了我以下错误:

Get-AzureWebSite:未找到请求的值“PremiumV2”

这个StackOverflow answer 建议改用Get-AzureRmWebApp,但这会给身份验证带来一些挑战。经过一番搜索,我找到了以下article,它准确地解释了我需要什么:一种无需任何人工交互即可发布到 Azure 的方法。

请看下面脚本的一个非常简化的版本。

#In the Azure portal go to (search for) "Azure Active Directory" -> 
#"Properties" -> Directory ID
$TenantId = "<Azure Active Directory Id>"

#In the Azure portal go to (search for) "Subscriptions" -> Subscription ID
$SubscriptionId = "<Azure Subscription Id>"

#In the Azure portal go to (search for) "Azure Active Directory" -> "App registrations" -> 
#Create a new registration, this will give you the ID and Secret below.
#Make sure to give your new app registration sufficient rights to your app service 
$ServicePrincipleApplicationId = "<Service Principle Id>"
$ServicePrincipleApplicationSecret = "<Service Principle Secret>"

$WebAppPath = "<Local folder where your package is located>"
$ResourceGroupName = "<The name of the Azure resource group that contains your app service>"
$WebAppName = "<The name of your Azure app service>"
$WebAppSlot = "<The name of the deployment slot you want to publish to>"

$MSDeployPath = "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe"
$source = "-source:contentPath=$WebAppPath"
$publishProfileOutputPath = Join-Path -Path $ENV:Temp -ChildPath 'publishprofile.xml'
$dest = "-dest:contentPath=d:\home\site\wwwroot\,publishSettings=$publishProfileOutputPath"
$SecurePassword = $ServicePrincipleApplicationSecret | ConvertTo-SecureString -AsPlainText -Force
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $ServicePrincipleApplicationId, $securePassword
$connectParameters = @{
    Credential     = $Credential
    TenantId       = $TenantId
    SubscriptionId = $SubscriptionId
}

Add-AzureRmAccount @connectParameters -ServicePrincipal

Get-AzureRmWebAppSlotPublishingProfile -OutputFile $publishProfileOutputPath -Format WebDeploy -ResourceGroupName $ResourceGroupName -Name $WebAppName -Slot $WebAppSlot

Stop-AzureRmWebAppSlot -ResourceGroupName $ResourceGroupName -Name $WebAppName -Slot $WebAppSlot

& $MSDeployPath @('-verb:sync', $source, $dest)

Start-AzureRmWebAppSlot -ResourceGroupName $ResourceGroupName -Name $WebAppName -Slot $WebAppSlot

【讨论】:

    【解决方案4】:

    使用 PowerShell cmdlet 将 zip 包部署到 Azure Web 应用服务。 ReferMS 文档。

    通过 PowerShell 连接到 Azure 订阅。执行 Publish-AzWebApp 部署 Web App。

    $webAppName = "<NameOfWebAppService>"
    $resourceGroup = "<WebAppResourceGroupName>"
    $zipArchiveFullPath = "<zip-package-filePath\FileName.zip>"
    Publish-AzWebApp -ResourceGroupName "$resourceGroup" -Name "$webAppName" -ArchivePath "$($zipArchiveFullPath)" -Force
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-07
      • 2020-07-30
      • 1970-01-01
      • 1970-01-01
      • 2016-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多