【问题标题】:Create / Config Azure Devops CI/CD deployment for Azure Webapp using ARM template or C# Sdk使用 ARM 模板或 C# Sdk 为 Azure Webapp 创建/配置 Azure Devops CI/CD 部署
【发布时间】:2019-07-08 08:01:52
【问题描述】:

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 documentation

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

【问题讨论】:

  • 我不确定这是否可能,因为您可以配置源,但我不知道如何配置凭据,它没有暴露在同一个 api 中。 here's 如何使用 arm 模板创建源代码控制。
  • 或许你可以试试 REST API Web Apps - Create Or Update Source Control
  • Charles Xu 已经尝试过了
  • Charles - 更新源代码控制不会使用 azure vsts/devops 设置持续部署。
  • @CharlesXu - 我找到了解决方案,请检查我的答案。

标签: azure azure-devops azure-web-app-service azure-resource-manager azure-cli


【解决方案1】:

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

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

有关预构建 ARM 模板的示例,请参阅此网页,其中包含超过 15 种可直接部署到 Azure 中的解决方案的指针,网址为: https://docs.microsoft.com/en-us/azure/app-service/samples-resource-manager-templates.

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

【讨论】:

    【解决方案2】:

    在本地系统上调试 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}"}}}'
    

    祝你好运!

    【讨论】:

      猜你喜欢
      • 2023-03-16
      • 1970-01-01
      • 1970-01-01
      • 2020-08-31
      • 1970-01-01
      • 2019-02-11
      • 2020-06-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多