代码之家  ›  专栏  ›  技术社区  ›  Tangiest

使用PowerShell将代码从GitLab存储库部署到Azure Web应用

  •  16
  • Tangiest  · 技术社区  · 8 年前

    https://christianliebel.com/2016/05/auto-deploying-to-azure-app-services-from-gitlab/

    不过,我正在尝试用Powershell实现自动化。我已经查看了GitHub的这个示例脚本:

    https://docs.microsoft.com/en-us/azure/app-service/scripts/app-service-powershell-continuous-deployment-github

    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)
    

    目前,我正在通过在GitHub中镜像我的GitLab存储库,并使用从那里到Azure的连续部署管道来解决这个问题。注意,这适用于托管在GitLab.com中的存储库,而不是自托管的GitLab服务器。项目没有Windows Runner安装程序。

    https://gitlab.com/MagicAndi/geekscode.net ),但这并不是解决方案使用私有存储库的特定要求(但如果是这样,那就更好了!)。

    更新日期:17/12/2018

    the-fish new question 使用azurecli和Powershell核心专门询问规范答案。我计划在两天后对我开放的时候为这个问题悬赏。谢谢。

    3 回复  |  直到 7 年前
        1
  •  2
  •   The Fish    7 年前

    $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
    

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

        2
  •  4
  •   Alex KeySmith    7 年前

    听起来你在寻找从GitLab到Azure应用的直接部署,但是我建议使用部署管道工具给你更多的选择。

    Azure DevOps Services 管道可能是一个安全的选择,并且有一个空闲层 very brief getting started guide for Web Apps deploys .

    marketplace tool for integrations with GitLab .

    这似乎不具备释放触发器的功能,但可以手动触发。其他人有这个问题 release triggers in the marketplace Q&A 所以也许它会出现在路线图中。

        3
  •  4
  •   Bsquare ℬℬ    7 年前

    为了重现您的情况,我使用了Azure CLI:

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

    可以在powershell的脚本中使用。

    首先,我尝试获取有关当前使用Bitbucket存储库部署的所有信息,该存储库配置为Microsoft.Web/sites/sourcecontrols/Bitbucket:

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

    得到了答案:

    {
      "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"
    }
    

    我断开了它的连接,并手动配置它,指定 就像在你的链接中一样,定义了相同的Git存储库和分支,最后,我得到了几乎相同的结果:

    {
      "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"
    }
    

    您可以看到不同之处:

    • 隐藏相关

    总之,您可以使用官方的Azure Cli和部署定义轻松编写脚本,方法如下:

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

    2018年11月15日编辑:

    需要注意的是,有时需要几分钟才能触发部署。

    最后,如果您想自动执行某个命令(Powershell命令、GNU/Bash脚本、.py、.bat或其他什么),您可以创建 .部署 文件位于存储库的根目录中。

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

    你可以在网上得到更多的信息 official documentation .