Deploy Code from GitLab Repository to Azure Web App using PowerShell

前端 未结 3 515
栀梦
栀梦 2021-01-04 01:15

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:

http

3条回答
  •  暖寄归人
    2021-01-04 01:34

    Trying to reproduce your situation, I used the Azure CLI:

    https://docs.microsoft.com/en-us/cli/azure/?view=azure-cli-latest
    

    Which is ready to be used in a script in powershell like you want.

    First, I tried to get all information about current deployment with a Bitbucket repository, which was configured as a Microsoft.Web/sites/sourcecontrols/Bitbucket:

    az webapp deployment source show --name XXXXXXX --resource-group YYYYY
    

    And got answer:

    {
      "branch": "master",
      "deploymentRollbackEnabled": false,
      "id": "/subscriptions/00000/resourceGroups/YYYYY/providers/Microsoft.Web/sites/XXXXXXX/sourcecontrols/web",
      "isManualIntegration": false,
      "isMercurial": false,
      "kind": null,
      "location": "North Europe",
      "name": "XXXXXXX",
      "repoUrl": "https://bitbucket.org/myAccount/myRepo",
      "resourceGroup": "YYYYY",
      "type": "Microsoft.Web/sites/sourcecontrols"
    }
    

    I disconnected it, and configured it manually, specifying External Repository exactly like in your link, defining the SAME Git repository, and branch, and at end, I got almost the same result:

    {
      "branch": "master",
      "deploymentRollbackEnabled": false,
      "id": "/subscriptions/00000/resourceGroups/YYYYY/providers/Microsoft.Web/sites/XXXXXXX/sourcecontrols/web",
      "isManualIntegration": true,
      "isMercurial": false,
      "kind": null,
      "location": "North Europe",
      "name": "XXXXXXX",
      "repoUrl": "https://bitbucket.org/myAccount/myRepo",
      "resourceGroup": "YYYYY",
      "tags": {
        "hidden-related:/subscriptions/00000/resourcegroups/YYYYY/providers/Microsoft.Web/serverfarms/XXXXXXX-sp": "empty"
      },
      "type": "Microsoft.Web/sites/sourcecontrols"
    }
    

    You can see the differences:

    • isManualIntegration is now True, instead of False
    • the hidden-related tag but I'm not sure it is interesting here

    All that to say, you can script easily, using the official Azure Cli, the deployment definition, this way:

    az webapp deployment source config --manual-integration --repository-type git --repo-url https://bitbucket.org/myAccount/myRepo --branch master --name XXXXXXX --resource-group YYYYY
    

    Edit 15/11/2018:

    Once this deployment setup done, each new commits push to the regarded branch (e.g. master in previous samples) will automatically trigger a new deployment.

    To be noted that sometimes it takes few minutes for the deployment to be triggered.

    Eventually, if ever you would like to automatically execute something (a Powershell command, a GNU/Bash script, an .py, .bat, or whatever), you can create a .deployment file in root of your repository.

    For instance:

    [config]
    SCM_COMMAND_IDLE_TIMEOUT = 9000
    command = bash.exe build_my_project_on_azure.sh
    

    You can get more information in the official documentation.

提交回复
热议问题