Mag*_*ndi 16 powershell azure gitlab
我想使用PowerShell脚本设置从GitLab存储库到Azure应用程序的持续部署.我知道您可以按照以下方式手动执行此操作:
https://christianliebel.com/2016/05/auto-deploying-to-azure-app-services-from-gitlab/
但是,我正在尝试使用Powershell自动执行此操作.我看过GitHub的这个示例脚本:
但由于没有GitLab的提供者,并且现有的提供者都没有接受GitLab URL,我不确定如何继续.我已经看过在Azure门户中使用GitLab设置手动部署(使用External Repository选项)并导出资源组模板以获取存储库如何连接到App的详细信息,但是我收到错误:
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)
Run Code Online (Sandbox Code Playgroud)
在那一刻,我正在解决这个问题,方法是在GitHub中镜像我的GitLab存储库,并使用从那里到Azure的持续部署管道.请注意,这适用于在GitLab.com中托管的存储库,而不是在自托管的GitLab服务器中.该项目没有Windows Runner设置.
如何使用PowerShell脚本直接从GitLab设置持续部署到Azure?运行安装脚本后,随后应将每个后续提交/合并到GitLab存储库的内容自动部署到Azure.最好,此PowerShell脚本应使用AzureRM模块,但我愿意接受使用PowerShell Core和新Az模块(基于Azure CLI)的解决方案.我正在使用的特定测试存储库是公共的(https://gitlab.com/MagicAndi/geekscode.net),但对于使用私有存储库的解决方案并不是特定的要求(但如果确实如此,那就更好了) !).
更新17/12/2018
由于他的答案最能满足我的特殊需求,因此我将奖金授予了鱼.但是,鉴于Windows Powershell和Azure RM模块被弃用而不支持PowerShell Core和新的Az模块(使用Azure CLI),我创建了一个新问题,特别要求使用Azure CLI和Powershell进行规范性回答核心.我计划在2天内向我敞开心扉,为这个问题提供赏金.谢谢.
假设存储库是公共的,您可以使用以下内容:
$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
Run Code Online (Sandbox Code Playgroud)
如果是私人的,请告诉我,这可能会更困难。如果您查看 CLI 源代码,您会发现它们当前仅支持 GitHub 的访问令牌。
| 归档时间: |
|
| 查看次数: |
1626 次 |
| 最近记录: |