如何基于Powershell脚本同步Azure AppService git?

Osc*_*ley 14 powershell azure azure-web-sites

我有一个从ARM模板创建的Azure AppService(Web站点微服务).它包含一个drupal应用程序.我已将其配置为从bitbucket中的git服务器读取.当我第一次创建时,它成功地从bitbucket(master分支)中提取文件.好的:-) App Service是使用PowerShell脚本创建的,该脚本使用从Jenkins项目启动的ARM模板.该项目名为ReCreateXXXAppService并执行PowerShell,该PowerShell检测AppService是否存在,如果是这种情况则删除它,然后再次部署它.

这是关于New-AzureRmResourceGroupDeployment的代码摘要:

    $repoUrl = "https://"+$AppServiceUsername+":"+$AppServicePassword+"@bitbucket.org/XXX/as-cms.git"
    $params = @{siteName=$AppServiceName ; hostingPlanName="$($AppServiceName)-HP"; siteLocation=$AppServiceLocationName; repoUrl=$repoUrl; branch="master";}
    $templateFile = Join-Path $scriptDir "templates\$TemplateName"
    Write-Host "Using template file $TemplateFile"
    New-AzureRmResourceGroupDeployment -Mode Complete -Force -TemplateParameterObject $params -Name "$($AppServiceName)-dn" -ResourceGroupName $azureResourceGroupName -TemplateFile $templateFile
Run Code Online (Sandbox Code Playgroud)

当我在master分支中更改某些内容时,我有两个选择:

  1. 自动化:在Jenkins中再次执行RecreateXXXAppService,等待大约1-2分钟(检测,删除和创建App Service时),我已部署更改.
  2. 手动:转到azure portal,选择App Service,Continuous Deployment并单击Sync.它只需要15-20秒.(查看截图)在此输入图像描述

我的问题是:

如何从PowerShell自动化相当于单击"同步"按钮?

注1:有一个类似的问题在这里,没有回答.

注2:源代码控制创建的模板部分是这样的:

      {
          "apiVersion": "2014-04-01",
          "name": "web",
          "type": "sourcecontrols",
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites', parameters('siteName'))]",
            "[concat('Microsoft.Web/Sites/', parameters('siteName'), '/config/web')]"
          ],
          "properties": {
            "RepoUrl": "[parameters('repoUrl')]",
            "branch": "[parameters('branch')]",
            "IsManualIntegration": true
          }
        }
Run Code Online (Sandbox Code Playgroud)

注3:我试过@MichaelB的答案没有运气.它似乎工作但不更新文件.输出是

Name              : as-xxxx-dev01
ResourceId        : /subscriptions/a303bbb8-8c07-wq10-8a6a-6c1eceef81bb/resourceGroups/as-rg-xxxx-EUN-DEV01/providers/Microsoft.Web/sites/as-cms-dev01/sourcecontrols/web
ResourceName      : as-xxxx-dev01/web
ResourceType      : Microsoft.Web/sites/sourcecontrols
ResourceGroupName : as-rg-xxxx-EUN-DEV01
Location          : North Europe
SubscriptionId    : a303ibb8-7i77-41d0-8a2s-6c1aaaaf81aa
Tags              : {System.Collections.Hashtable}
Properties        : @{RepoUrl=https://deployments:*******@bitbucket.org/project/as-xxxx.git; Branch=master; IsManualIntegration=False; DeploymentRollbackEnabled=False; 
                    IsMercurial=False; ProvisioningState=Succeeded}
Run Code Online (Sandbox Code Playgroud)

Mic*_*l B 5

刚刚遇到类似的情况,似乎这是解决方案(或至少是解决方案)

如果你最初删除了repo,然后重新添加它,它显然会强制重新同步.

Remove-AzureRmResource -ResourceGroupName $AppServiceResourceGroupName `
                -ResourceType Microsoft.Web/sites/SourceControls `
                -Name $AppServiceWebAppName/Web `
                -ApiVersion 2015-08-01 `
                -Force


$props = @{
    RepoUrl = "https://github.com/{account}/{repo}"
    Branch = "master"
    isManualIntegration = "false" 
}
########## -- Configure Source Control --##########
New-AzureRmResource -ResourceGroupName $AppServiceResourceGroupName `
                -ResourceType Microsoft.Web/sites/SourceControls `
                -Name $AppServiceWebAppName/Web `
                -PropertyObject $props `
                -ApiVersion 2015-08-01 `
                -Force
Run Code Online (Sandbox Code Playgroud)