how to read input from System variable while creating deployment through ARM template - azure

I am trying to deploy Ms Sql server by using Azure Cli and ARM template. When i execute the ARM template, it asks me for input parameters like administratorLogin, administratorLoginPassword, serverName. Below is the example:
root#649e67dacd8f:~/.jenkins/workspace/Terraform# az group deployment create --resource-group Arm-template --template-uri https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-sql-logical-server/azuredeploy.json --verbose
Please provide string value for 'serverName' (? for help): chitender
Please provide string value for 'administratorLogin' (? for help): chitender
Please provide securestring value for 'administratorLoginPassword' (? for help):
So I need to input the parameters at runtime.
Now I am trying to automate it through Jenkins build project, so that I get administratorLogin, administratorLoginPassword, serverName input from user who is executing the Jenkins job and ARM template read this input through system variables instead of asking for input in runtime.
So i want to know is there any possible ways where I can enter the input variables through System global variables?

You can use the following command to achieve this.
az group deployment create --resource-group Arm-template --template-uri https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-sql-logical-server/azuredeploy.json --parameters administratorLogin=$administratorLogin administratorLoginPassword=$administratorLoginPassword serverName=$serverName --verbose
which $administratorLogin is the related variable.

Related

Microsoft Azure: 'New-AzResourceGroupDeployment : A parameter cannot be found that matches parameter name 'location'

I'm a beginner at Microsoft Azure so please bear with me. I'm following this tutorial on deploying bicep templates with parameters, my bicep file is the exact same as the one in the tutorial. However, when I attempt to deploy it I get the following error
New-AzResourceGroupDeployment : A parameter cannot be found that matches parameter name 'location'.
The location parameter definitely exists. I'm deploying with the following command:
New-AzResourceGroupDeployment -ResourceGroupName ResourceGroup -TemplateFile c:\Users\Name\Desktop\files\azure\testing\test.bicep -location region -storagename storageaccountname -storagetype Standard_LRS -WhatIf
Any help would be appreciated!
It looks like the tutorial contains an error. In the official documentation, there is no location parameter in the New-AzResourceGroupDeployment cmdlet.
Also, you have already specified a resource group, and the resources you describe with bicep contain a location. So the location parameter makes no sense here - just leave it out!
Note that you can also deploy your bicep files using the Azure CLI. See Deploy local Bicep file
A way to not have to put in the location for a resource if you have all resources in the same location is to make use of
So as long as you have run this command, it will apply for all bicep files you run with it configured as such:
This means you don't need to provide it with every CLI command for bicep.
I followed this tutorial series and found it fantastic:
Beginner
Intermediate
Advanced
What the New-AzResourceGroupDeployment command allows you to do is supply parameter values via PowerShell params. So while the command has its own parameters and location is not one of them, any extra parameters supplied to the command are passed as template parameters. If the template does not have a parameter named location (for example) - you'll see that error.
That error is usually pretty accurate, so the template may very well not have a parameter named location. Check to make sure the file c:\Users\Name\Desktop\files\azure\testing\test.bicep has a location param, and that you've saved the file since changing it (I forget that often).
If that doesn't unblock, share your file/code and that may help debug.

How to get value from Azure App Service from Azure pipeline

I have a configuration in App Service like this
I want to pass this setting into the argument of a pipeline's task
How can I do it?
I've tried to create a variable group but I still don't know how to link the app setting into the variable
Microsoft provide command line tools to access this information. I don't have a web-app to access to give specific commands but roughly something like this.
See documentation here: https://learn.microsoft.com/en-us/azure/app-service/configure-common?tabs=cli#configure-app-settings
For example using az cli you could do something like:
az webapp config connection-string list --resource-group <group-name> --name <app-name> > settings.json
You can then select the specific item out of that list using jq.
myvalue=$(jq -r .some.path settings.json)
And you can also set the value in a variable which you can use in another task:
##vso[task.setvariable variable=appsetting;]value
So :
Download app settings
Select item
Set variable to pass to next step
Use variable in next step.

Unable to use output variables from a PowerShell script in the Override Parameters of a Resource Group deployment task in Azure DevOPS

I have a PowerShell script where I have multiple output variables generated with the following syntax :
Write-Host ("##vso[task.setvariable variable=appObjectId;issecret=false]"+$appObjectId)
In the PowerShell task in Azure DevOPS, I have set the Output variables as follow:
Then, I use my output variables in an Azure Resource Group deployment as follow:
Unfortunately, when I look into the deployment details in Azure, I can see that the parameters of my ARM are not filled out with the value of the output parameters but with the name of it:
Important information: the ARM deployment task is done inside a task group. My PowerShell script is in the pipeline, just before the call to the Task Group. I tried to put the script inside the Task Group but I have the exact same issue.
I found the root cause: I need to enclose the parameter "$(myParam)" in the tasks where I need to use it. Otherwise, it is not computed.
I think you might have gotten the format wrong for defining the output variable from your Powershell script, this should work -
Write-Host "##vso[task.setvariable variable=appObjectId;isOutput=true]$appObjectId"
Update
Also add is isoutput=true, the defaults to false.
Cause you are not set the variable to appObjectId correctly. There is not AADApplication.appClientid. Then Azure DevOps treat this to string. That's why the parameters of my ARM are not filled out with the value of the output parameters but with the name of it.
No need to use () to include the follow set variable command.
SetVariable: Initialize or modify the value of a variable
##vso[task.setvariable]value
You should use the following syntax :
Write-Host "##vso[task.setvariable variable=appClientID;issecret=false;isoutput=true]value"
More details please refer our official doc here.

Azure Team Services CI - Release Variable does not work

I am trying to automate resource group creation with team services release.
I added azure resource group project to the solution and defined administratorLoginPassword variable as a secure string in json definition:
Also I defined administratorLoginPassword variable at the environment level in release definition as the following:
But when I run release it fails with the following reason:
Cannot process command because of one or more missing mandatory
parameters: administratorLoginPassword.
You need to pass that variable explicitly to the template script specifying its value in the Override Template Parameters text box, as follow:
-administratorLoginPassword (ConvertTo-SecureString -String '$(administratorLoginPassword)' -AsPlainText -Force)
Anyway I would suggest to create a proper azuredeploy.parameters.json file where you store all the actual values for all the required template parameters, and pass this file to Template Parameters input of the Azure Resource Group Deployment task. This file could be manipulated during build/release by replacing the content with the values you need, avoiding entirely to play with special parameters of the build task.
The variables created in the Build/Release Definition are disregarded by the Azure Res. Group Deployment task unless you pass it over explicitly as shown above.

Escape Dollar $ sign in Azure ARM Template Variable

I have an ARM Template to deploy a WebApp in Azure. I also have a AppSettings configuration in WebApp (which is used for sending emails) "EmailPassword" to be deployed along with the ARM Template.
The actual value for variable "EmailPassword" is"Test$am123" in ARM Template.
But when I execute the ARM Template during deployment, the value is stored as "Test123" in the AppSettings of the created WebApp.
I hope this happens because of the $ (dollar) sign in the variable.
How to escape the Dollar sign in the ARM Template variables
Update: With the help of 4c74356b41, I found the Issue is not with ARM Template and its Parameters.Json. Instead, I am using the VSO Deployment and trying to pass the values to Parameters from the Environment Variables. I overriding the Parameters.json using the "Override Template Parameters" input in VSO.
The Issue is with VSO and it removes the "$am" characters while passing the values to the ARM Deployment.
I think that escaping is done using \ character.
update: for me $ doesnt need escaping.

Resources