繁体   English   中英

使用ARM模板或C#SDK为Azure Webapp创建/配置Azure Devops CI / CD部署

[英]Create / Config Azure Devops CI/CD deployment for Azure Webapp using ARM template or C# Sdk

在从Cloud Shell运行时,下面的命令可从Azure DevOps项目正确设置CI / CD

az login

az webapp deployment source config --name "{azurewebappname}" --resource-group "{webappunderresourcegroupname}" --repository-type vsts --repo-url "https://{accountname}.visualstudio.com/{projectname}/_git/{reponame}" --branch master --cd-app-type AspNetCore --cd-project-url "https://{accountname}.visualstudio.com/{projectname}"  --subscription "{subscriptionid}"  --private-repo-password "{vsts-alias-username}" --private-repo-username "{vsts-alias-password}"

我正在寻找通过ARM模板C#SDKREST API等效的解决方案。

Azure-Cli文档

注意:我正在通过C#使用ARM模板

在C#中,这里有一个工作代码示例用于部署ARM模板。 该示例将登录Azure,创建资源组,部署ARM模板,然后删除该模板。

请注意,此示例使用AzureCredentialsFactory从文件获取Azure凭据。 为了完成授权部分,我发现创建服务主体,将凭据保存到安全文件并在应用程序中使用它是最简单的。 有关有效的代码示例,请查看[here][3]

有关预构建的ARM模板的示例,请访问以下网页,该网页包含指向可以直接部署到Azure的15种以上解决方案的指针, 网址为: https : //docs.microsoft.com/zh-cn/azure/app-service/样品资源管理器模板。

我相信您感兴趣的是: here ,它部署了一个连接到github存储库的webapp。

在本地系统上调试Azure CLI之后,查看azure-cli发送/接收问题的命令的请求/响应,可以在请求流下面找到-可能会有所帮助。

# 1. Get tenant's access token - not covered here, check microsoft's ADAL documentation.
# 2. Get vsts access token
curl -X POST \
https://login.microsoftonline.com/common/oauth2/token \  
-H 'content-type: application/x-www-form-urlencoded' \  
-d 'grant_type=refresh_token&resource=499b84ac-1321-427f-aa17-267ca6975798&refresh_token={insert_tenant_refresh_token_here}&client_id=04b07795-8ddb-461a-bbee-02f9e1bf7b46'


# 3. Provision CI/CD configuration
curl -X POST 'https://{insert_azuredevops_account_name}.portalext.visualstudio.com/_apis/continuousdelivery/provisioningconfigurations?api-version=3.2-preview.1' \
 -H 'authorization: Bearer {insert_tenant_access_token_here}' \
 -H 'content-type: application/json' \
 -d '{"source": {"type": "codeRepository", "buildConfiguration": {"type": "AspNetCore"}, "repository": {"defaultBranch": "master", "type": "TfsGit", "id": "{insert_repository_id}"}}, "targets": [{"environmentType": "production", "authorizationInfo": {"scheme": "Headers", "parameters": {"Authorization": "Bearer {insert_vsts_access_token}"}}, "resourceGroupName": "{insert_webapp_resource_group_name}", "tenantId": "{insert_tenant_id}", "location": "Central India", "subscriptionName": "{insert_azure_webapp_subscription_name}", "provider": "azure", "friendlyName": "Production", "subscriptionId": "{insert_azure_webapp_subscription_id}", "resourceIdentifier": "{insert_azure_webapp_name}", "type": "windowsAppService"}], "ciConfiguration": {"project": {"name": "{insert_vsts_project_name}"}}}'

祝好运!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM