I have an Azure AppService (Web-Site microservice) created from an ARM template. It contains a drupal app. I have configured it to read from a git server in bitbucket. When I create for first time it sucessfully pull the files from bitbucket (master branch). All good :-) The App Service is created from a PowerShell script that uses ARM templates launched from Jenkins project. The project is called ReCreateXXXAppService and executes a PowerShell that detects if AppService is there, delete it if that is the case, and deploy it again.
This is the summary of my code around 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
When I change something in master branch I have two options:
My question is:
How can I automate from PowerShell the equivalent of clicking "Sync" button?
NOTE1: There is a similar question here, with no answer.
NOTE2: The template part for source control creation is this one:
{
"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
}
}
NOTE3: I tried @MichaelB answer with no luck. It seems working but doesn't update the files. Output is
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}
Having just come across a similar situation myself, it seems this is the solution (or at least, a solution)
If you initially delete the repo, and then re-add it, it will - obviously - force a resync.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With