0

I created a Function App through GitHub Action workflow and an ARM Template from Azure. It is a CI/CD workflow.

To deploy the Function App directly, I go to Deployment Center manually connect to GitHub. Then get the Publish Profile settings, and update the GitHub secret.

The manual process works! But if it is part of the ARM Template, the workflow fails.

enter image description here

I see a section in the ARM Template like below:

{
                    "type": "sourcecontrols",
                    "name": "web",
                    "apiVersion": "2020-12-01",
                    "properties": {
                        "RepoUrl": "[parameters('repoUrl')]",
                        "branch": "[parameters('branch')]",
                        "IsManualIntegration": false,
                        "deploymentRollbackEnabled": false,
                        "isMercurial": false,
                        "isGitHubAction": true,
                        "gitHubActionConfiguration": {
                            "generateWorkflowFile": false,
                            "workflowSettings": {
                                "appType": "functionapp",
                                "publishType": "code",
                                "os": "linux",
                                "runtimeStack": "dotnet",
                                "workflowApiVersion": "2020-12-01",
                                "slotName": "production",
                                "variables": {
                                    "runtimeVersion": "7.0.x"
                                }
                            }
                        }
                    },
                    "dependsOn": [
                        "[resourceId('Microsoft.Web/Sites', parameters('name'))]"
                    ]
                }

But the above generates the error:

ERROR: ***"status":"Failed","error":***"code":"DeploymentFailed","target":"/subscriptions/f24b12b1-d887-4938-8c49-ce56acded667/resourceGroups/MyResourceGroup/providers/Microsoft.Resources/deployments/azure-function-api","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-deployment-operations for usage details.","details":[***"code":"NotFound","target":"/subscriptions/f24b12b1-d887-4938-8c49-ce56acded667/resourceGroups/MyResourceGroup/providers/Microsoft.Resources/deployments/azure-function-api","message":"***\r\n  \"Code\": \"NotFound\",\r\n  \"Message\": \"Cannot find SourceControlToken with name GitHub.\",\r\n  \"Target\": null,\r\n  \"Details\": [\r\n    ***\r\n      \"Message\": \"Cannot find SourceControlToken with name GitHub.\"\r\n    ***,\r\n    ***\r\n      \"Code\": \"NotFound\"\r\n    ***,\r\n    ***\r\n      \"ErrorEntity\": ***\r\n        \"ExtendedCode\": \"51004\",\r\n        \"MessageTemplate\": \"Cannot find ***0*** with name ***1***.\",\r\n        \"Parameters\": [\r\n          \"SourceControlToken\",\r\n          \"GitHub\"\r\n        ],\r\n        \"Code\": \"NotFound\",\r\n        \"Message\": \"Cannot find SourceControlToken with name GitHub.\"\r\n      ***\r\n    ***\r\n  ],\r\n  \"Innererror\": null\r\n***"***]***

What configuration that I need to have so I can pass the above error?

Instead of the manual step, are there ARM Template commands to get the GitHub repository name, branch and copy the secret to the GitHub Settings\Secrets & Variables as Repository secrets?

wonderful world
  • 10,969
  • 20
  • 97
  • 194

1 Answers1

1

I tried the below ARM Template and added my repository URL that contains the Function and Branch in the source control parameter section of the template and tried deploying it, The Function Trigger got deployed successfully, Refer below:-

ARM template reference Link

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "appName": {
            "defaultValue": "[concat('funtionapp-', uniqueString(resourceGroup().id))]",
            "type": "string",
            "metadata": {
                "description": "The name of the function app that you wish to create."
            }
        },
        "sku": {
            "defaultValue": "S1",
            "type": "string",
            "metadata": {
                "description": "The pricing tier for the hosting plan."
            }
        },
        "workerSize": {
            "defaultValue": "0",
            "allowedValues": [
                "0",
                "1",
                "2"
            ],
            "type": "String",
            "metadata": {
                "description": "The instance size of the hosting plan (small, medium, or large)."
            }
        },
        "storageAccountType": {
            "defaultValue": "Standard_LRS",
            "allowedValues": [
                "Standard_LRS",
                "Standard_GRS",
                "Standard_ZRS",
                "Premium_LRS"
            ],
            "type": "string",
            "metadata": {
                "description": "Storage Account type"
            }
        },
        "repoURL": {
            "defaultValue": "https://github.com/username/FunctionApp25",
            "type": "string",
            "metadata": {
                "description": "The URL for the GitHub repository that contains the project to deploy."
            }
        },
        "branch": {
            "defaultValue": "master",
            "type": "string",
            "metadata": {
                "description": "The branch of the GitHub repository to use."
            }
        },
        "location": {
            "defaultValue": "[resourceGroup().location]",
            "type": "string",
            "metadata": {
                "description": "Location for all resources."
            }
        }
    },
    "variables": {
        "functionAppName": "[parameters('appName')]",
        "hostingPlanName": "[concat(parameters('appName'), '-plan')]",
        "storageAccountName": "[concat(uniquestring(resourceGroup().id), 'functions')]"
    },
    "resources": [
        {
            "type": "Microsoft.Storage/storageAccounts",
            "apiVersion": "2021-02-01",
            "name": "[variables('storageAccountName')]",
            "location": "[parameters('location')]",
            "sku": {
                "name": "[parameters('storageAccountType')]"
            },
            "kind": "Storage"
        },
        {
            "type": "Microsoft.Web/serverfarms",
            "apiVersion": "2020-12-01",
            "name": "[variables('hostingPlanName')]",
            "location": "[parameters('location')]",
            "sku": {
                "name": "[parameters('sku')]"
            },
            "properties": {
                "workerSize": "[parameters('workerSize')]",
                "numberOfWorkers": 1
            }
        },
        {
            "type": "Microsoft.Web/sites",
            "apiVersion": "2020-12-01",
            "name": "[variables('functionAppName')]",
            "location": "[parameters('location')]",
            "dependsOn": [
                "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
                "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
            ],
            "kind": "functionapp",
            "properties": {
                "name": "[variables('functionAppName')]",
                "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
                "clientAffinityEnabled": false,
                "siteConfig": {
                    "alwaysOn": true,
                    "cors": {
                        "allowedOrigins": [
                            "*"
                        ]
                    },
                    "appSettings": [
                        {
                            "name": "FUNCTIONS_EXTENSION_VERSION",
                            "value": "~1"
                        },
                        {
                            "name": "AzureWebJobsStorage",
                            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',variables('storageAccountName'),';AccountKey=',listkeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), '2019-06-01').keys[0].value,';')]"
                        },
                        {
                            "name": "AzureWebJobsDashboard",
                            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',variables('storageAccountName'),';AccountKey=',listkeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), '2019-06-01').keys[0].value,';')]"
                        }
                    ]
                }
            },
            "resources": [
                {
                    "type": "sourcecontrols",
                    "apiVersion": "2020-12-01",
                    "name": "web",
                    "dependsOn": [
                        "[resourceId('Microsoft.Web/Sites', variables('functionAppName'))]"
                    ],
                    "properties": {
                        "RepoUrl": "[parameters('repoURL')]",
                        "branch": "[parameters('branch')]",
                        "IsManualIntegration": true
                    }
                }
            ]
        }
    ]
}

enter image description here

You can check your Function deployment logs here and see if any settings needs to be changed, or any issue that is stopping the deployment from source control via github actions.

enter image description here

Function Trigger got deployed from my github repository successfully like below:-

Added CORS setting like below:-

enter image description here

enter image description here

In-order to deploy ARM template via Portal, Use the method below:-

Select Custom Deployment in Azure Portal > Build your own template in the editor> Add the ARM template above and deploy, Make sure you replace the repo_urrl and branch with yours in parameter:-

enter image description here

enter image description here

Click on Save, Select Resource Group > Review + Create > And the Function app with Trigger will be deployed:-

enter image description here

enter image description here

SiddheshDesai
  • 3,668
  • 1
  • 2
  • 11
  • When I have "IsManualIntegration": true, I get the error ```Operation not supported: ManualIntegration does not support GitHubAction.```. If I have that value as false, I get the error ```Cannot find SourceControlToken with name GitHub.```. My GitHubAction login to the Azure with a Service Principal which has contributor role. It can create all the resources that I want except connecting to the GitHub. If I run it manually to connect which I can. That manual process may be using my admin AD account that I use to login to Azure. – wonderful world Jul 22 '23 at 15:44
  • Do you a have solution to fix the error ```Cannot find SourceControlToken with name GitHub.```? – wonderful world Jul 25 '23 at 01:25
  • 1
    For this you need to download Publish Profile from Your Azure Function app Overview page and add it as a secret in the Github repository > settings > Secrets > Actions and then add that variable in the Github action workflow for the workflow to work – SiddheshDesai Jul 25 '23 at 03:33
  • 1
    Refer this github action workflow script here-https://github.com/Azure/actions-workflow-samples/blob/master/FunctionApp/windows-dotnet-functionapp-on-azure.yml and samples here- https://github.com/Azure/functions-action – SiddheshDesai Jul 25 '23 at 03:35
  • I have to manually add the GitHub information on the ```Deployment Center``` page and then ```Download Publish Profile. I don't think you had to follow that step. My ARM template is generated from Azure and is almost like you. But you don't get the error message, but my script does. Is this due to I use ```Service Principal```? – wonderful world Jul 25 '23 at 10:24
  • 1
    Yes, It might be because of your service principal. As I don't get any error – SiddheshDesai Jul 25 '23 at 10:30
  • Is there any documentation on using ```Servive Principal``` when creating ```source controls``` resources and what configuration need to be followed? – wonderful world Jul 25 '23 at 10:50