在Azure DevOps管道中为WebApp创建部署插槽

时间:2020-03-16 14:24:09

标签: azure azure-devops yaml azure-pipelines

我想从Azure DevOps管道执行以下操作:

  • 为现有WebApp(staging)创建新的部署槽位
  • 将应用程序部署到新插槽
  • staging交换production插槽
  • 删除以前的production,现在删除staging插槽

到目前为止,我有:

  • 将应用程序部署到新插槽
  • 用生产交换staging位置
  • 删除以前的production,现在删除staging插槽

YAML:

- task: AzureRmWebAppDeployment@4
  inputs:
    ConnectionType: 'AzureRM'
    azureSubscription: 'BizSpark(...)'
    appType: 'webApp'
    WebAppName: 'foo'
    deployToSlotOrASE: true
    ResourceGroupName: 'Default-WestEurope'
    SlotName: 'staging'
    packageForLinux: '$(Build.ArtifactStagingDirectory)/**/*.zip'

- task: AzureAppServiceManage@0
  inputs:
    azureSubscription: 'BizSpark(..)'
    Action: 'Swap Slots'
    WebAppName: 'foo'
    ResourceGroupName: 'Default-WestEurope'
    SourceSlot: 'staging'

- task: AzureAppServiceManage@0
  inputs:
    azureSubscription: 'BizSpark(..)'
    Action: 'Delete Slot'
    WebAppName: 'foo'
    ResourceGroupName: 'Default-WestEurope'
    Slot: 'staging'

但是,AzureAppServiceManage任务没有提供创建部署槽的方法。

这怎么办?

2 个答案:

答案 0 :(得分:3)

在Azure DevOps管道中为WebApp创建部署插槽

恐怕没有这样的现成方法可以在Azure DevOps管道中为WebApp创建部署插槽。

作为任务Azure App Service Management的{​​{3}},我们可以知道:

Azure App Service管理任务用于启动/停止/重新启动 应用服务,交换版位,安装扩展,启用连续 监视或启动/停止Azure应用上的所有连续WebJob 服务。

它不支持在Azure devops管道中为WebApp创建部署插槽。而且AFAIK,Azure devops管道中目前没有其他任务支持此功能。

作为此问题的解决方案,就像juunas注释一样,通常,这是通过ARM模板部署来实现的。

我们可以使用以下ARM模板为Azure App Service设置部署槽:

{
    "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "siteName": {
            "type": "string"
        },
        "slotName": {
            "type": "string"
        }
    },
    "resources": [
        {
            "apiVersion": "2015-04-01",
            "type": "Microsoft.Web/Sites/Slots",
            "name": "[concat(parameters('siteName'), '/', parameters('slotName'))]",
            "location": "[resourceGroup().location]",
            "properties": {},
            "resources": []
        }
    ]
}

然后,我们可以使用Azure devops部署ARM模板。

您可以查看statethis blog了解更多详细信息。

希望这会有所帮助。

答案 1 :(得分:2)

我可以使用powershell和Microsft Hosted Agent在azure devops管道中创建一个WebbApp插槽,这是任务:

按照documentation example

- task: AzureCLI@2
    displayName: Azure CLI   
     inputs:
      azureSubscription: <Name of the Azure Resource Manager service connection>
      scriptType: ps
      scriptLocation: inlineScript
      inlineScript: |
          az --version
          az account show

对于内联脚本,我使用了“ az webapp部署槽创建” Azure CLI Command

az webapp deployment slot create --name
                                 --resource-group
                                 --slot
                                 [--configuration-source]
                                 [--subscription]

这有帮助吗?