Specifying artifactsLocation in web app deployment to Azure - azure

I am trying to deploy an Azure Resource group via Octopus Deploy (within it a website).
Hyak.Common.CloudException: InvalidTemplate: Deployment template validation failed: 'The value for the template parameter '_artifactsLocation' at line '40' and column '32' is not provided.
How would I specify this in Visual Studio so that the solution can get deployed to Azure?
Thanks

From an Octopus point-of-view, you can use variable substitution on both the Template and Parameter files to sub in whatever values you need to your templates.
If you have a look at the "Template Contained in a Package" section of the Azure Resource Groups documentation, it shows you example JSON templates with variable substitution in place.
Eg.
"databaseName": {
"value": "#{DatabaseName}"
},
So in your project, you'd setup a project variable, then use the variable substitution syntax to address that variable in your template JSON (that's contained in your package), and it will get substituted before being executed at Azure.
Hope this helps

Related

Azure resource manager template deployments - Using _artifactsLocation and _artifactsLocationSasToken

Where and how to use artifactsLocation and _artifactsLocationSasToken in Arm template deployments. Are these used only for nested deployments.
Can we use these for custom VM extension of the Virtual machine as part of post provisioning activity, after VM is built or should the extension be added as part of the VM build deployment template only.
VM Custom script extension - (Initialize and format data drives, Mount file shares for instance)
Azure quick start templates, have the parameter values for these as default for artifactsLocation and type securestring for _artifactsLocationSasToken. How these values are populated in the ARM deployment runtime.
It would be great if someone can provide documentation around the same / step by step process or share an existing working custom script extension template.
There's nothing inherent in the platform that makes _artifactsLocation and _artifactsLocationSasToken special... it's just a pattern (well used) that has developed for staging artifacts needed for a deployment. The pattern is to stage all artifacts together and then use the uri of the main template as a relative location. The defaultValue generally used for _artifactsLocation is:
"defaultValue": "[deployment().properties.templateLink.uri]"
The deployment() function is inherent and contains the uri passed in for the main template.
That said, you can use those values anyway you see fit and the primary use case is for retrieving any artifact needed by any resource. For example:
Custom Script Extension
https://github.com/Azure/azure-quickstart-templates/blob/master/demos/vm-winrm-windows/azuredeploy.json#L256-L259
MSDeploy Packages for WebApps
https://github.com/Azure/azure-quickstart-templates/blob/master/demos/private-endpoint-sql-from-appservice/azuredeploy.json#L277
DSC Configuration Modules
https://github.com/Azure/azure-quickstart-templates/blob/master/demos/iis-2vm-sql-1vm/azuredeploy.json#L585
etc, etc...
That help?

Azure Data Factory Release Pipeline - Resource Not Found Error

I am testing a build/release of a very simple ADF (just one activity), the build, repository, arm template export all seem ok until when I run the release task, the error shows up in the final step, that says:
"error": {
"code": "ResourceNotFound",
"message": "The Resource 'Microsoft.DataFactory/factories/htTestDF' under resource group 'xxx-rg' was not found."
}
I watched several tutorials and microsoft web sites, and tried exporting the ARM template several times, the same error occurs. Any ideas will be greatly appreciated.
Thanks for your details clarifies in comments. Now, the error message you met caused by using a different target resource group as this ARM template deploy to.
To make this more clear, I reproduce the issue based on the details you provided. Fortunately, got the same error with you. Now, let's focus on its log, then get why it cause the Not Found error.(Please set debug=true)
As I mentioned in the above pic, it is the api that this task used at first step while the template begin to apply into the corresponding resource group and deployment. For more cleared, please refer to this REST API doc firstly: Deployments - Create Or Update.
The logic of this task is compile parameters from ARM template file, pack them and use it as request body for this PUT api call. See its api doc, you can get that for this API call, its resourceGroupName and deploymentName need to be specified firstly. In another words, if you specified another target resource group, it would not find the correct target place that can apply this template definition. Because, you can see that this ARM template is preparing to applying activities SetVariable into your Data Factory HTDF3 and the defined pipelines name is HTPipe1. But these should all not exists in your target Resource Group. Thus it caused the error like this:
"error": {
"code": "ResourceNotFound",
"message": "The Resource 'Microsoft.DataFactory/factories/Merlin-1003' under resource group 'Merlin-ARM-deploy' was not found."
}
In my sample, Merlin-ARM-deploy is my target resource group.
If you want to deploy this into your target resource group, you need to create one data factory manually, or use another ARM Template to create a new one same factory in the target resource group. If you choose the previous method, just then modify the template.json file, to let its parameters correspond to the actual target resource group. But if use the second method, do not operate anything. Just apply them with task.
The ARM template generated by ADF(publish) cannot be deployed directly to a new RG.
Solution
Create RG(optional, assuming it is IAC(infra as code))
Run a powershell script task in pipeline to create an empty ADF(do not use empty ARM instead). Since it is not ARM you would need to put an optional condition to check if it already exists)
Set-AzDataFactoryV2 -ResourceGroupName "RG" -Name "ADF" -Location "North Europe"
Now we can execute the ARM template from publish folder (the one you had given)
Errors in ADF publish system.
The ARM template need to be generated in such a way that it is
idempotent(should also create afresh if not present). But it is not
at the moment. It expects an ADF to be present already(strangely).
When an empty ARM template created in another RG is used to create a fresh empty ADF in this RG(newly created), it fails. Well, it creates empty ADF but we cannot put adf_publish(default publish folder for ADF) on top of it because we get 'resource not found error'.
But when we manually create an ADF and run the adf_publish template
then it works! But ofcourse, this is not what we want.
Why does manual & powershell work(empty + publish) but not ARM template? It could be that the ARM Template has wrong location/region mentioned in it but that was not the case.(really puzzling to me)

Build arm template in VSTS fails with error about 'artifactsLocation'

Normally when i deploy through visual studio _artifactsLocation shows when editing the parameters so what should this be in VSTS and how do I set it?
2018-02-21T08:49:46.1918199Z ##[error]Deployment template validation failed: 'The value for the template parameter '_artifactsLocation' at line '1' and column '182' is not provided. Please see https://aka.ms/arm-deploy/#parameter-file for usage details.'.
2018-02-21T08:49:46.1919769Z ##[error]Task failed while creating or updating the template deployment.
You can specify it in parameters file, then specify the file path in Template parameters input box of Azure Resource Group Deployment task if you are using.
Also, the parameters can be override by specifying in Override template parameters input box of Azure Resource Group Deployment task.
If you are calling script through Azure PowerShell task, you can specify it in the arguments: -ArtifactStagingDirectory, related issue: The value for the template parameter '_artifactsLocation' is not provided
This sounds like you are using the Azure Resource Group deployment template from VS to deploy via VSTS.
It uses MSDeploy as part of the ARM template deployment to deploy your service.
The Powershell script that is generated by the VS project template uploads a ZIP-file containing your service to Blob storage, and puts the URL and other information into _artifactsLocation and other ARM template parameters.
Instead of doing that, you can remove the artifacts related parameters and the MSDeploy resource from the ARM template. Then the template ONLY contains infrastructure related resources.
After this, add a "Deploy to App Service" step in the VSTS Release pipeline after the ARM template deployment. That can then be used to deploy your service code.
If you are using a separate parameters json file, you'll need to initialise the _artifactsLocation and _artifactsLocationSasToken there. You can give them empty strings, like:
"_artifactsLocation": {
"value": ""
},
"_artifactsLocationSasToken": {
"value": ""
},
They should automatically get their values from a PowerShell script. I'm using the AzureResourceManagerTemplateDeployment#3 task, it would probably work with AzureResourceGroupDeployment#2 as well.

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