azure-web-app-serviceazure-resource-managerazure-management-apiazure-rest-api

How Can I deploy Apps in app service with private GitHub repository using REST API or ARM templates?


The following is the ARM template I am using to create a app service and use a private GitHub repo to deploy applications with deployment for application fails.

{
               "properties": {
               "mode": "Incremental",
               "template":{
                "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
                "contentVersion": "1.0.0.1",
                "parameters": {
                    "siteName": {
                        "type": "string",
                        "defaultValue": "[concat(\'WebApp-\', uniqueString(resourceGroup().id))]",
                        "metadata": {
                            "description": "The name of you Web Site."
                        }
                    },
                    "location": {
                        "type": "string",
                        "defaultValue": "[resourceGroup().location]",
                        "metadata": {
                            "description": "Location for all resources."
                        }
                    },
                    "sku": {
                        "type": "string",
                        "allowedValues": [
                            "F1",
                            "D1",
                            "B1",
                            "B2",
                            "B3",
                            "S1",
                            "S2",
                            "S3",
                            "P1",
                            "P2",
                            "P3",
                            "P4"
                        ],
                        "defaultValue": "F1",
                        "metadata": {
                            "description": "The pricing tier for the hosting plan."
                        }
                    },
                    "workerSize": {
                        "type": "string",
                        "allowedValues": [
                            "0",
                            "1",
                            "2"
                        ],
                        "defaultValue": "0",
                        "metadata": {
                            "description": "The instance size of the hosting plan (small, medium, or large)."
                        }
                    },
                    "repoURL": {
                        "type": "string",
                        "defaultValue": "https://github.com/Azure-Samples/app-service-web-html-get-started.git",
                        "metadata": {
                            "description": "The URL for the GitHub repository that contains the project to deploy."
                        }
                    },
                    "branch": {
                        "type": "string",
                        "defaultValue": "master",
                        "metadata": {
                            "description": "The branch of the GitHub repository to use."
                        }
                    }
                },
                "variables": {
                    "hostingPlanName": "jhyhfgljgljuhg-Plan"
                },
                "resources": [
                    {
                        "type": "Microsoft.Web/serverfarms",
                        "apiVersion": "2020-06-01",
                        "name": "[variables(\'hostingPlanName\')]",
                        "location": "[parameters(\'location\')]",
                        "sku": {
                            "name": "[parameters(\'sku\')]",
                            "capacity": "[parameters(\'workerSize\')]"
                        },
                        "properties": {
                            "name": "[variables(\'hostingPlanName\')]"
                        }
                    },
                    {
                        "type": "Microsoft.Web/sites",
                        "apiVersion": "2020-06-01",
                        "name": "[parameters(\'siteName\')]",
                        "location": "[parameters(\'location\')]",
                        "identity": {
                            "type": "SystemAssigned"
                      },
                        "dependsOn": [
                            "[resourceId(\'Microsoft.Web/serverfarms\', variables(\'hostingPlanName\'))]"
                        ],
                        "properties": {
                            "serverFarmId": "[variables(\'hostingPlanName\')]"
                        },
                        "resources": [
                            {
                                "type": "sourcecontrols",
                                "apiVersion": "2020-06-01",
                                "name": "web",
                                "location": "[parameters(\'location\')]",
                                "dependsOn": [
                                    "[resourceId(\'Microsoft.Web/sites\', parameters(\'siteName\'))]"
                                ],
                                "properties": {
                                    "repoUrl": "[parameters(\'repoURL\')]",
                                    "branch": "[parameters(\'branch\')]",
                                    "isManualIntegration": true,
                                    "ScmType":"Git"
                                }
                            }
                        ]
                    }
                ]
            },
               "parameters": {
                 "siteName": {
                   "value":"trouble1appservice"
               },
                 "repoUrl": {
                "value":"https://trouble1fake:8f0276be40aaed284ac8862d198fb1e1a17f727f@github.com/trouble1fake/uploadfile"
             },
        "sku": {
              "value": "B1"
            },
            "workerSize": {
              "value": "0"
            },
            "branch": {
              "value": "master"
            }
                    }
                }
            }
        }

repoUrl I am using is https://trouble1fake:8f0276be40aaed284ac8862d198fb1e1a17f727f@github.com/trouble1fake/uploadfile

Still its not working. Or is there any way I can execute commands or import files using rest api?


Solution

  • This is not how it works. You have to create artifacts of your GitHub solution first and then deploy it (be it local or pipelines). Pls refer to below approaches and choose the one you desire:

    1. You can use Visual Studio to deploy your App, once it is cloned in your local from your private repository: Deploy an ASP.NET Web App in Azure App Service

    2. You can deploy your app using Azure DevOps pipelines, wherein you can add your code in the ADO server and follow the step-by-step process to deploy the app: Deploying into Azure App Service using Azure DevOps CI/CD Pipeline.