Passing custom parameters to powershell script inside of ARM template for Microsoft.Web/sites/functions

Ray Marr 96 Reputation points
2020-05-28T15:46:06.263+00:00

Is there any way to pass in runtime parameters to a function app which runs a powershell script which is set up using ARM templates?

Here is a function I am deploying which works, as long as I don't use 'customVariable', but I want to be able to use customVariable in my Powershell script and don't know how to pass it in using the armTemplate. I am using a release pipeline (Azure resource group deployment) to deploy the ARM template, incase that helps.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "existingFunctionAppName": {
      "type": "string",
      "metadata": {
        "description": "The name of the function container in which the function has to be created."
      }
    },
    "functionName": {
      "type": "string",
      "defaultValue": "getStyleSheet",
      "metadata": {
        "description": "The name of the function."
      }
    },
    "customVariable": {
      "type": "string",
      "defaultValue": "some value",
      "metadata": {
        "description": "A variable I want to use in my powershell script."
      }
    }
  },
  "resources": [
    {
      "apiVersion": "2015-08-01",
      "name": "[concat(parameters('existingFunctionAppName'),'/', parameters('functionName'))]",
      "type": "Microsoft.Web/sites/functions",
      "properties": {
        "config": {
          "bindings": [
            {
              "name": "Request",
              "direction": "in",
              "type": "httpTrigger",
              "methods": ["get", "post"]
            },
            {
              "name": "Response",
              "direction": "out",
              "type": "http"
            }
          ]
        },
        "files": {
          "run.ps1": "param($Request, $TriggerMetadata, $customVariable) \r\n #do something with customVariable"
        }
      }
    }
  ]
}
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,829 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ray Marr 96 Reputation points
    2020-05-29T10:55:51.95+00:00

    I found an easy solution for my needs, setting environment variables when deploying function app, and then accessing the environment variables in my PS script with $env:MY_VARIABLE

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Birendra Singh 181 Reputation points
    2020-05-28T18:03:20.397+00:00

    $using:uservariable

    0 comments No comments