Deploy Code from GitLab Repository to Azure Web App using PowerShell

MagicAndi

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:

https://docs.microsoft.com/en-us/azure/app-service/scripts/app-service-powershell-continuous-deployment-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.

The Fish

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.

https://github.com/Azure/azure-cli/blob/4f87cb0d322c60ecc6449022467bd580a0accd57/src/command_modules/azure-cli-appservice/azure/cli/command_modules/appservice/custom.py#L964-L1027

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Azure DevOps unable to deploy to Azure Web App

分類Dev

Using Azure Active Directory authentication in ASP.NET Core 2.0 from Web App to Web API

分類Dev

Spring boot app deploy to appengine from azure dev ops

分類Dev

Build and Deploy Azure Functions App from Build Server

分類Dev

Azure Web App logout from AAD Authentication

分類Dev

Deploy app from CircleCI with

分類Dev

upload files to Azure file storage from web app using rest api

分類Dev

How to tail log from go app on Azure Web App

分類Dev

Azure DevOps CI/CD Deploy Web or Function App changing the values in appsettings in YAML Pipelines

分類Dev

How to close web browser window from code behind page after form post request completes, in razor web app using .netcore

分類Dev

gitlab - Push to a repository using access_token

分類Dev

Cannot connect to Azure SQL using PowerShell in an MSI enabled function app

分類Dev

webadmin deploy to azure from github

分類Dev

How can I deploy a new version of a google apps web app using the new editor

分類Dev

Creating resource groups from Azure Web App Managed Service Identity

分類Dev

Web API + Azure App Insights pass the data from ActionFilter to ITelemetryProcessor

分類Dev

How to auto deploy on ec2 using gitlab runners?

分類Dev

Deploy ASP.NET Core 5 app to Azure App Service?

分類Dev

Deploy ASP.NET Core 5 app to Azure App Service?

分類Dev

Adding an App Settings to existing Azure Web Application using Azure Power Shell

分類Dev

Binding input from Azure blob in function app using python

分類Dev

Unable to clone repository from Gitlab: Permission denied, please try again

分類Dev

How to access web api from another web app which is in same Azure AD?

分類Dev

Switch from web-view to app view using Javascript

分類Dev

Accessing web app running in a VM from host using SSH tunnel

分類Dev

Azure Web App Code Not Updating After Publish Until Restart (VS2017)

分類Dev

How to get the souce code from Git/Mercurial repository using Bitbucket/SourceTree to a specific date

分類Dev

How to Deploy Lambdas from one code base?

分類Dev

How to add app roles under manifest in Azure Active Directory using Powershell script

Related 関連記事

  1. 1

    Azure DevOps unable to deploy to Azure Web App

  2. 2

    Using Azure Active Directory authentication in ASP.NET Core 2.0 from Web App to Web API

  3. 3

    Spring boot app deploy to appengine from azure dev ops

  4. 4

    Build and Deploy Azure Functions App from Build Server

  5. 5

    Azure Web App logout from AAD Authentication

  6. 6

    Deploy app from CircleCI with

  7. 7

    upload files to Azure file storage from web app using rest api

  8. 8

    How to tail log from go app on Azure Web App

  9. 9

    Azure DevOps CI/CD Deploy Web or Function App changing the values in appsettings in YAML Pipelines

  10. 10

    How to close web browser window from code behind page after form post request completes, in razor web app using .netcore

  11. 11

    gitlab - Push to a repository using access_token

  12. 12

    Cannot connect to Azure SQL using PowerShell in an MSI enabled function app

  13. 13

    webadmin deploy to azure from github

  14. 14

    How can I deploy a new version of a google apps web app using the new editor

  15. 15

    Creating resource groups from Azure Web App Managed Service Identity

  16. 16

    Web API + Azure App Insights pass the data from ActionFilter to ITelemetryProcessor

  17. 17

    How to auto deploy on ec2 using gitlab runners?

  18. 18

    Deploy ASP.NET Core 5 app to Azure App Service?

  19. 19

    Deploy ASP.NET Core 5 app to Azure App Service?

  20. 20

    Adding an App Settings to existing Azure Web Application using Azure Power Shell

  21. 21

    Binding input from Azure blob in function app using python

  22. 22

    Unable to clone repository from Gitlab: Permission denied, please try again

  23. 23

    How to access web api from another web app which is in same Azure AD?

  24. 24

    Switch from web-view to app view using Javascript

  25. 25

    Accessing web app running in a VM from host using SSH tunnel

  26. 26

    Azure Web App Code Not Updating After Publish Until Restart (VS2017)

  27. 27

    How to get the souce code from Git/Mercurial repository using Bitbucket/SourceTree to a specific date

  28. 28

    How to Deploy Lambdas from one code base?

  29. 29

    How to add app roles under manifest in Azure Active Directory using Powershell script

ホットタグ

アーカイブ