question

RayMarr-5085 avatar image
0 Votes"
RayMarr-5085 asked azure-cxp-api edited

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

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-webapps
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RayMarr-5085 avatar image
0 Votes"
RayMarr-5085 answered

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

BIRENDRA avatar image
0 Votes"
BIRENDRA answered

$using:uservariable

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.