I would like to setup continuous deployment from a GitLab repository to an Azure App using a PowerShell script. I'm aware that you can do this manually as per:
https://christianliebel.com/2016/05/auto-deploying-to-azure-app-services-from-gitlab/
However, I'm trying to automate this with Powershell. I've looked at this sample script for GitHub:
But as there is no provider for GitLab, and none of the existing providers accept a GitLab URL, I'm unsure of how to proceed. I've looked at setting up a manual deployment with GitLab in the Azure Portal (using the External Repository option) and exporting the resource group template to get details of how the repository is connected to the App, but I get the error:
Could not get resources of the type 'Microsoft.Web/sites/sourcecontrols'.
Resources of this type will not be exported. (Code: ExportTemplateProviderError, Target: Microsoft.Web/sites/sourcecontrols)
At the minute, I'm working around this by mirroring my GitLab repository in GitHub, and using the continuous deployment pipeline from there to Azure. Note, this is for a repository hosted in GitLab.com, not in a self-hosted GitLab server. There is no Windows Runner setup for the project.
How can I use a PowerShell script to setup a Continuous Deployment directly from GitLab to Azure? Once the setup script is run, each subsequent commit/merge to the GitLab repository should then automatically be deployed to Azure. Preferably, this PowerShell script should use the AzureRM modules, but I'm willing to accept a solution that uses PowerShell Core and the new Az module (based on the Azure CLI). The specific test repository I'm using is public (https://gitlab.com/MagicAndi/geekscode.net), but it isn't a specific requirement for the solution to work with private repositories (but if it does, even better!).
Update 17/12/2018
I've awarded the bounty to the-fish as his answer best met my specific needs. However, given that Windows Powershell and the Azure RM module are being deprecated in favour of PowerShell Core and the new Az module (using the Azure CLI), I've created a new question asking specificially for a canonical answer using the Azure CLI and Powershell Core. I plan on offering a bounty for this question when it is open to me in 2 days. Thanks.
Assuming the repository is public you could use the following:
$gitrepo="<replace-with-URL-of-your-own-repo>"
$webappname="mywebapp$(Get-Random)"
$location="West Europe"
# Create a resource group.
New-AzureRmResourceGroup -Name myResourceGroup -Location $location
# Create an App Service plan in Free tier.
New-AzureRmAppServicePlan -Name $webappname -Location $location `
-ResourceGroupName myResourceGroup -Tier Free
# Create a web app.
New-AzureRmWebApp -Name $webappname -Location $location -AppServicePlan $webappname `
-ResourceGroupName myResourceGroup
# Configure deployment from your repo and deploy once.
$PropertiesObject = @{
repoUrl = "$gitrepo";
branch = "master";
isManualIntegration = $true
}
Set-AzureRmResource -PropertyObject $PropertiesObject -ResourceGroupName myResourceGroup `
-ResourceType Microsoft.Web/sites/sourcecontrols -ResourceName $webappname/web `
-ApiVersion 2018-02-01 -Force
Let me know if it's private, that may be more difficult. If you look at the CLI source you can see they currently only support access tokens with GitHub.
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加