From b3df7f04c4a003c50762002d5301fd7226bfca33 Mon Sep 17 00:00:00 2001 From: t-dedah Date: Tue, 18 Jan 2022 03:02:05 +0530 Subject: [PATCH 01/19] Added support for bicep files --- .../operations/DeploymentScopeBase.ts | 3 +- .../operations/ResourceGroup.ts | 1 + .../operations/Utils.ts | 73 ++++++++++++++++++- .../task.json | 9 ++- .../task.loc.json | 9 ++- 5 files changed, 89 insertions(+), 6 deletions(-) diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/operations/DeploymentScopeBase.ts b/Tasks/AzureResourceManagerTemplateDeploymentV3/operations/DeploymentScopeBase.ts index f654aebfc49d..da9a02b6021d 100644 --- a/Tasks/AzureResourceManagerTemplateDeploymentV3/operations/DeploymentScopeBase.ts +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/operations/DeploymentScopeBase.ts @@ -21,13 +21,14 @@ export class DeploymentScopeBase { public async deploy(): Promise { await this.createTemplateDeployment(); + utils.deleteGeneratedFiles() } protected async createTemplateDeployment() { console.log(tl.loc("CreatingTemplateDeployment")); var params: DeploymentParameters; if (this.taskParameters.templateLocation === "Linked artifact") { - params = utils.getDeploymentDataForLinkedArtifact(this.taskParameters); + params = await utils.getDeploymentDataForLinkedArtifact(this.taskParameters); } else if (this.taskParameters.templateLocation === "URL of the file") { params = await utils.getDeploymentObjectForPublicURL(this.taskParameters); } else { diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/operations/ResourceGroup.ts b/Tasks/AzureResourceManagerTemplateDeploymentV3/operations/ResourceGroup.ts index ece98e6fe41d..c45be0d71766 100644 --- a/Tasks/AzureResourceManagerTemplateDeploymentV3/operations/ResourceGroup.ts +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/operations/ResourceGroup.ts @@ -17,6 +17,7 @@ export class ResourceGroup extends DeploymentScopeBase { public async deploy(): Promise { await this.createResourceGroupIfRequired(); await this.createTemplateDeployment(); + utils.deleteGeneratedFiles() } public deleteResourceGroup(): Promise { diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/operations/Utils.ts b/Tasks/AzureResourceManagerTemplateDeploymentV3/operations/Utils.ts index 9ce8c52da667..0db4272f9efc 100644 --- a/Tasks/AzureResourceManagerTemplateDeploymentV3/operations/Utils.ts +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/operations/Utils.ts @@ -10,6 +10,7 @@ import { TemplateObject, ParameterValue } from "../models/Types"; import httpInterfaces = require("typed-rest-client/Interfaces"); import { DeploymentParameters } from "./DeploymentParameters"; +var cpExec = util.promisify(require('child_process').exec); var hm = require("typed-rest-client/HttpClient"); var uuid = require("uuid"); @@ -33,6 +34,8 @@ function formatNumber(num: number): string { } class Utils { + public static cleanupFileList = [] + public static isNonEmpty(str: string): boolean { return (!!str && !!str.trim()); } @@ -222,7 +225,7 @@ class Utils { return deploymentName; } - public static getDeploymentDataForLinkedArtifact(taskParameters: armDeployTaskParameters.TaskParameters): DeploymentParameters { + public static async getDeploymentDataForLinkedArtifact(taskParameters: armDeployTaskParameters.TaskParameters): Promise { var template: TemplateObject; var fileMatches = tl.findMatch(tl.getVariable("System.DefaultWorkingDirectory"), this.escapeBlockCharacters(taskParameters.csmFile)); if (fileMatches.length > 1) { @@ -234,6 +237,7 @@ class Utils { var csmFilePath = fileMatches[0]; if (!fs.lstatSync(csmFilePath).isDirectory()) { tl.debug("Loading CSM Template File.. " + csmFilePath); + csmFilePath = await this.getFilePathForLinkedArtifact(csmFilePath) try { template = JSON.parse(this.stripJsonComments(fileEncoding.readFileContentsAsText(csmFilePath))); } @@ -257,6 +261,7 @@ class Utils { var csmParametersFilePath = fileMatches[0]; if (!fs.lstatSync(csmParametersFilePath).isDirectory()) { tl.debug("Loading Parameters File.. " + csmParametersFilePath); + csmParametersFilePath = await this.getFilePathForLinkedArtifact(csmParametersFilePath) try { var parameterFile = JSON.parse(this.stripJsonComments(fileEncoding.readFileContentsAsText(csmParametersFilePath))); tl.debug("Loaded Parameters File"); @@ -285,6 +290,16 @@ class Utils { return deploymentParameters; } + public static deleteGeneratedFiles(): void{ + this.cleanupFileList.forEach(filePath => { + try{ + fs.unlinkSync(filePath); + }catch(err){ + console.log(tl.loc("BicepFileCleanupFailed", err)) + } + }); + } + private static getPolicyHelpLink(taskParameters: armDeployTaskParameters.TaskParameters, errorDetail) { var additionalInfo = errorDetail.additionalInfo; if (!!additionalInfo) { @@ -407,6 +422,62 @@ class Utils { private static escapeBlockCharacters(str: string): string { return str.replace(/[\[]/g, '$&[]'); } + + private static async getFilePathForLinkedArtifact(filePath: string): Promise { + var filePathExtension: string = filePath.split('.').pop(); + if(filePathExtension === 'bicep'){ + let azcliversion = await this.getAzureCliVersion() + if(parseFloat(azcliversion)){ + if(this.isBicepAvailable(azcliversion)){ + await this.execBicepBuild(filePath) + filePath = filePath.replace('.bicep', '.json') + this.cleanupFileList.push(filePath) + }else{ + throw new Error(tl.loc("IncompatibleAzureCLIVersion")); + } + }else{ + throw new Error(tl.loc("AzureCLINotFound")); + } + } + return filePath + } + + private static async getAzureCliVersion(): Promise { + let azcliversion: string = "" ; + try { + const { stdout, stderr } = await cpExec('az version'); + if (!stderr) { + azcliversion = JSON.parse(stdout)["azure-cli"] + } else { + throw stderr + } + } catch (err) { + throw new Error(tl.loc("FailedToFetchAzureCLIVersion", err)); + } + return azcliversion + } + + private static async execBicepBuild(filePath): Promise { + try { + const { stdout, stderr } = await cpExec(`az bicep build --file ${filePath}`); + if (!stderr) { + } else { + throw stderr + } + } catch (err) { + throw new Error(tl.loc("BicepBuildFailed", err)); + } + } + + private static isBicepAvailable(azcliversion): Boolean{ + let majorVersion = azcliversion.split('.')[0] + let minorVersion = azcliversion.split('.')[1] + // Support Bicep was introduced in az-cli 2.20.0 + if(majorVersion >= 2 && minorVersion >= 20){ + return true + } + return false + } } export = Utils; \ No newline at end of file diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/task.json b/Tasks/AzureResourceManagerTemplateDeploymentV3/task.json index 3d874338e35d..589857ec52a8 100644 --- a/Tasks/AzureResourceManagerTemplateDeploymentV3/task.json +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/task.json @@ -14,7 +14,7 @@ "author": "Microsoft Corporation", "version": { "Major": 3, - "Minor": 198, + "Minor": 199, "Patch": 0 }, "demands": [], @@ -309,6 +309,11 @@ "ManagedServiceIdentityDetails": "Please make sure the Managed Service Identity used for deployment is assigned the right roles for the Resource Group %s. Follow the link for more details: https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/howto-assign-access-portal", "CompleteDeploymentModeNotSupported": "Deployment mode 'Complete' is not supported for deployment at '%s' scope", "TemplateValidationFailure": "Validation errors were found in the Azure Resource Manager template. This can potentially cause template deployment to fail. %s. Please follow https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/template-syntax", - "TroubleshootingGuide": "Check out the troubleshooting guide to see if your issue is addressed: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-resource-group-deployment?view=azure-devops#troubleshooting" + "TroubleshootingGuide": "Check out the troubleshooting guide to see if your issue is addressed: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-resource-group-deployment?view=azure-devops#troubleshooting", + "IncompatibleAzureCLIVersion": "Azure CLI version should be >= 2.20.0", + "AzureCLINotFound": "Azure CLI not found on the agent.", + "FailedToFetchAzureCLIVersion": "Failed to fetch az cli version from agent. Error: %s", + "BicepBuildFailed": "\"az bicep build\" failed. Error: %s", + "BicepFileCleanupFailed": "Failed to delete bicep file. Error: %s" } } \ No newline at end of file diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/task.loc.json b/Tasks/AzureResourceManagerTemplateDeploymentV3/task.loc.json index 055dbb205b75..bcf54b533514 100644 --- a/Tasks/AzureResourceManagerTemplateDeploymentV3/task.loc.json +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/task.loc.json @@ -14,7 +14,7 @@ "author": "Microsoft Corporation", "version": { "Major": 3, - "Minor": 198, + "Minor": 199, "Patch": 0 }, "demands": [], @@ -309,6 +309,11 @@ "ManagedServiceIdentityDetails": "ms-resource:loc.messages.ManagedServiceIdentityDetails", "CompleteDeploymentModeNotSupported": "ms-resource:loc.messages.CompleteDeploymentModeNotSupported", "TemplateValidationFailure": "ms-resource:loc.messages.TemplateValidationFailure", - "TroubleshootingGuide": "ms-resource:loc.messages.TroubleshootingGuide" + "TroubleshootingGuide": "ms-resource:loc.messages.TroubleshootingGuide", + "IncompatibleAzureCLIVersion": "ms-resource:loc.messages.IncompatibleAzureCLIVersion", + "AzureCLINotFound": "ms-resource:loc.messages.AzureCLINotFound", + "FailedToFetchAzureCLIVersion": "ms-resource:loc.messages.FailedToFetchAzureCLIVersion", + "BicepBuildFailed": "ms-resource:loc.messages.BicepBuildFailed", + "BicepFileCleanupFailed": "ms-resource:loc.messages.BicepFileCleanupFailed" } } \ No newline at end of file From 1ef0e6bb130ebcc52722259cf524338186293644 Mon Sep 17 00:00:00 2001 From: t-dedah Date: Tue, 18 Jan 2022 03:50:07 +0530 Subject: [PATCH 02/19] Added tests and updated documentation --- .../README.md | 2 +- .../Tests/L0.ts | 20 +++++++++++++++++++ .../task.json | 4 ++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/README.md b/Tasks/AzureResourceManagerTemplateDeploymentV3/README.md index c07255e9d89b..61275de5bc5d 100644 --- a/Tasks/AzureResourceManagerTemplateDeploymentV3/README.md +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/README.md @@ -52,7 +52,7 @@ The parameters of the task are described in details, including examples, to show - For Resource Group deployment scope: Location for deploying the resource group. If the resource group already exists in the subscription, then this value will be ignored. - For other deployment scopes: Location for storing the deployment metadata. - * **Template location**: The location of the Template & the Parameters JSON files. Select "Linked Artifact" if the files are part of the linked code/build artifacts. Select "URL of the file" if the JSON files are located at any publicly accessible http/https URLs. To use a file stored in a private storage account, retrieve and include the shared access signature (SAS) token in the URL of the template. Example: /template.json?. To upload a parameters file to a storage account and generate a SAS token, you could use [Azure file copy task](https://aka.ms/azurefilecopyreadme) or follow the steps using [PowerShell](https://go.microsoft.com/fwlink/?linkid=838080) or [Azure CLI](https://go.microsoft.com/fwlink/?linkid=836911). + * **Template location**: The location of the Template & the Parameters JSON files. Select "Linked Artifact" if the files are part of the linked code/build artifacts. For "Linked Artifacts", we can also use biceps files. Select "URL of the file" if the JSON files are located at any publicly accessible http/https URLs. To use a file stored in a private storage account, retrieve and include the shared access signature (SAS) token in the URL of the template. Example: /template.json?. To upload a parameters file to a storage account and generate a SAS token, you could use [Azure file copy task](https://aka.ms/azurefilecopyreadme) or follow the steps using [PowerShell](https://go.microsoft.com/fwlink/?linkid=838080) or [Azure CLI](https://go.microsoft.com/fwlink/?linkid=836911). * **Template and its Parameters**: The templates and the templates parameters file are the Azure templates available at [GitHub](https://github.com/Azure/azure-quickstart-templates) or in the [Azure gallery](https://azure.microsoft.com/en-in/documentation/articles/powershell-azure-resource-manager/). To get started immediately use [this](https://aka.ms/sampletemplate) template that is available on GitHub. - These files can be either be located at any publicly accessible http/https URLs or be in a checked in the Version Control or they can be part of the build itself. If the files are part of the Build, use the pre-defined [system variables](https://msdn.microsoft.com/Library/vs/alm/Build/scripts/variables) provided by the Build to specify their location. The variables to use are $(Build.Repository.LocalPath), if the templates are checked-in but are not built, or $(Agent.BuildDirectory), if the templates are built as part of the solution. Be sure to specify the full path like $(Build.Repository.LocalPath)\Azure Templates\AzureRGDeploy.json. Wildcards like \*\*\\\*.json or \*\*\\*.param.json are also supported and there needs to be only one file that matches the search pattern at the location. If more than one file matches the search pattern, then the task will error out. diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts b/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts index a47595a0fc2c..88cdffae01ac 100644 --- a/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts @@ -172,4 +172,24 @@ describe('Azure Resource Manager Template Deployment', function () { done(error); } }); + + it('Successfully triggered createOrUpdate deployment using bicep file', (done) => { + let tp = path.join(__dirname, 'createOrUpdate.js'); + process.env["csmFile"] = "CSM.bicep"; + process.env["deploymentOutputs"] = "someVar"; + let tr = new ttm.MockTestRunner(tp); + tr.run(); + try { + assert(tr.succeeded, "Should have succeeded"); + assert(tr.stdout.indexOf("properly sanitized") > 0, "Parameters should have been sanitized"); + assert(tr.stdout.indexOf("deployments.createOrUpdate is called") > 0, "deployments.createOrUpdate function should have been called from azure-sdk"); + assert(tr.stdout.indexOf("##vso[task.setvariable variable=someVar;]") >= 0, "deploymentsOutput should have been updated"); + done(); + } + catch (error) { + console.log("STDERR", tr.stderr); + console.log("STDOUT", tr.stdout); + done(error); + } + }); }); diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/task.json b/Tasks/AzureResourceManagerTemplateDeploymentV3/task.json index 589857ec52a8..aa773d4333dd 100644 --- a/Tasks/AzureResourceManagerTemplateDeploymentV3/task.json +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/task.json @@ -161,7 +161,7 @@ "required": true, "groupName": "Template", "visibleRule": " templateLocation = Linked artifact", - "helpMarkDown": "Specify the path or a pattern pointing to the Azure Resource Manager template. For more information about the templates see https://aka.ms/azuretemplates. To get started immediately use template https://aka.ms/sampletemplate." + "helpMarkDown": "Specify the path or a pattern pointing to the Azure Resource Manager template. For more information about the templates see https://aka.ms/azuretemplates. To get started immediately use template https://aka.ms/sampletemplate. 'Linked artifact' also have support for bicep files with azure cli version > 2.20.0" }, { "name": "csmParametersFile", @@ -170,7 +170,7 @@ "defaultValue": "", "required": false, "groupName": "Template", - "helpMarkDown": "Specify the path or a pattern pointing for the parameters file for the Azure Resource Manager template.", + "helpMarkDown": "Specify the path or a pattern pointing for the parameters file for the Azure Resource Manager template. 'Linked artifact' also have support for bicep files with azure cli version > 2.20.0", "visibleRule": " templateLocation = Linked artifact" }, { From 58a1961d2c2e02aec07063dbb340f64fb87ff86e Mon Sep 17 00:00:00 2001 From: t-dedah Date: Tue, 18 Jan 2022 04:10:01 +0530 Subject: [PATCH 03/19] Added CSM.bicep file --- .../Tests/CSM.bicep | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/CSM.bicep diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/CSM.bicep b/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/CSM.bicep new file mode 100644 index 000000000000..ad2523a9f7b9 --- /dev/null +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/CSM.bicep @@ -0,0 +1,18 @@ +param location string = 'eastasia' + +var storageAccountName_var = 'deepak2121' +var storageAccountType = 'Premium_LRS' + +resource storageAccount 'Microsoft.Storage/storageAccounts@2021-01-01' = { + name: toLower(take(storageAccountName_var, 24)) + location: location + sku: { + name: storageAccountType + } + kind: 'StorageV2' +} + +output storageAccount_Name string = storageAccount.name +output storageAccount_Location string = storageAccount.location +output storageAccount_SKUName string = storageAccount.sku.name +output storageAccount_Kind string = storageAccount.kind \ No newline at end of file From e22f0b9f325a769a214e6d5eccc91fbafb359594 Mon Sep 17 00:00:00 2001 From: Deepak Dahiya <59823596+t-dedah@users.noreply.github.com> Date: Tue, 18 Jan 2022 04:18:29 +0530 Subject: [PATCH 04/19] Update Tasks/AzureResourceManagerTemplateDeploymentV3/task.json Co-authored-by: John Downs --- Tasks/AzureResourceManagerTemplateDeploymentV3/task.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/task.json b/Tasks/AzureResourceManagerTemplateDeploymentV3/task.json index aa773d4333dd..334598424dbb 100644 --- a/Tasks/AzureResourceManagerTemplateDeploymentV3/task.json +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/task.json @@ -161,7 +161,7 @@ "required": true, "groupName": "Template", "visibleRule": " templateLocation = Linked artifact", - "helpMarkDown": "Specify the path or a pattern pointing to the Azure Resource Manager template. For more information about the templates see https://aka.ms/azuretemplates. To get started immediately use template https://aka.ms/sampletemplate. 'Linked artifact' also have support for bicep files with azure cli version > 2.20.0" + "helpMarkDown": "Specify the path or a pattern pointing to the Azure Resource Manager template. For more information about the templates see https://aka.ms/azuretemplates. To get started immediately use template https://aka.ms/sampletemplate. 'Linked artifact' also has support for Bicep files when the Azure CLI version > 2.20.0" }, { "name": "csmParametersFile", From fdb3ff076e75ba067e0092ba8df191eb806911f7 Mon Sep 17 00:00:00 2001 From: Deepak Dahiya <59823596+t-dedah@users.noreply.github.com> Date: Tue, 18 Jan 2022 04:18:40 +0530 Subject: [PATCH 05/19] Update Tasks/AzureResourceManagerTemplateDeploymentV3/task.json Co-authored-by: John Downs --- Tasks/AzureResourceManagerTemplateDeploymentV3/task.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/task.json b/Tasks/AzureResourceManagerTemplateDeploymentV3/task.json index 334598424dbb..0fdb511902e3 100644 --- a/Tasks/AzureResourceManagerTemplateDeploymentV3/task.json +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/task.json @@ -170,7 +170,7 @@ "defaultValue": "", "required": false, "groupName": "Template", - "helpMarkDown": "Specify the path or a pattern pointing for the parameters file for the Azure Resource Manager template. 'Linked artifact' also have support for bicep files with azure cli version > 2.20.0", + "helpMarkDown": "Specify the path or a pattern pointing for the parameters file for the Azure Resource Manager template. 'Linked artifact' also has support for Bicep files when the Azure CLI version > 2.20.0", "visibleRule": " templateLocation = Linked artifact" }, { From 91642278f1a466655a602cc6df90eb5ecaac0891 Mon Sep 17 00:00:00 2001 From: Deepak Dahiya <59823596+t-dedah@users.noreply.github.com> Date: Tue, 18 Jan 2022 04:18:46 +0530 Subject: [PATCH 06/19] Update Tasks/AzureResourceManagerTemplateDeploymentV3/task.json Co-authored-by: John Downs --- Tasks/AzureResourceManagerTemplateDeploymentV3/task.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/task.json b/Tasks/AzureResourceManagerTemplateDeploymentV3/task.json index 0fdb511902e3..4eb9c380bb37 100644 --- a/Tasks/AzureResourceManagerTemplateDeploymentV3/task.json +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/task.json @@ -314,6 +314,6 @@ "AzureCLINotFound": "Azure CLI not found on the agent.", "FailedToFetchAzureCLIVersion": "Failed to fetch az cli version from agent. Error: %s", "BicepBuildFailed": "\"az bicep build\" failed. Error: %s", - "BicepFileCleanupFailed": "Failed to delete bicep file. Error: %s" + "BicepFileCleanupFailed": "Failed to delete Bicep file. Error: %s" } } \ No newline at end of file From 4350db892b041ba0327e92464fddd3810dd11e4c Mon Sep 17 00:00:00 2001 From: Deepak Dahiya <59823596+t-dedah@users.noreply.github.com> Date: Tue, 18 Jan 2022 04:19:10 +0530 Subject: [PATCH 07/19] Update Tasks/AzureResourceManagerTemplateDeploymentV3/README.md Co-authored-by: John Downs --- Tasks/AzureResourceManagerTemplateDeploymentV3/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/README.md b/Tasks/AzureResourceManagerTemplateDeploymentV3/README.md index 61275de5bc5d..3af25178c4d2 100644 --- a/Tasks/AzureResourceManagerTemplateDeploymentV3/README.md +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/README.md @@ -52,7 +52,7 @@ The parameters of the task are described in details, including examples, to show - For Resource Group deployment scope: Location for deploying the resource group. If the resource group already exists in the subscription, then this value will be ignored. - For other deployment scopes: Location for storing the deployment metadata. - * **Template location**: The location of the Template & the Parameters JSON files. Select "Linked Artifact" if the files are part of the linked code/build artifacts. For "Linked Artifacts", we can also use biceps files. Select "URL of the file" if the JSON files are located at any publicly accessible http/https URLs. To use a file stored in a private storage account, retrieve and include the shared access signature (SAS) token in the URL of the template. Example: /template.json?. To upload a parameters file to a storage account and generate a SAS token, you could use [Azure file copy task](https://aka.ms/azurefilecopyreadme) or follow the steps using [PowerShell](https://go.microsoft.com/fwlink/?linkid=838080) or [Azure CLI](https://go.microsoft.com/fwlink/?linkid=836911). + * **Template location**: The location of the Template & the Parameters JSON files. Select "Linked Artifact" if the files are part of the linked code/build artifacts. For "Linked Artifacts", you can also specify the path to a Bicep file. Select "URL of the file" if the JSON files are located at any publicly accessible http/https URLs. To use a file stored in a private storage account, retrieve and include the shared access signature (SAS) token in the URL of the template. Example: /template.json?. To upload a parameters file to a storage account and generate a SAS token, you could use [Azure file copy task](https://aka.ms/azurefilecopyreadme) or follow the steps using [PowerShell](https://go.microsoft.com/fwlink/?linkid=838080) or [Azure CLI](https://go.microsoft.com/fwlink/?linkid=836911). * **Template and its Parameters**: The templates and the templates parameters file are the Azure templates available at [GitHub](https://github.com/Azure/azure-quickstart-templates) or in the [Azure gallery](https://azure.microsoft.com/en-in/documentation/articles/powershell-azure-resource-manager/). To get started immediately use [this](https://aka.ms/sampletemplate) template that is available on GitHub. - These files can be either be located at any publicly accessible http/https URLs or be in a checked in the Version Control or they can be part of the build itself. If the files are part of the Build, use the pre-defined [system variables](https://msdn.microsoft.com/Library/vs/alm/Build/scripts/variables) provided by the Build to specify their location. The variables to use are $(Build.Repository.LocalPath), if the templates are checked-in but are not built, or $(Agent.BuildDirectory), if the templates are built as part of the solution. Be sure to specify the full path like $(Build.Repository.LocalPath)\Azure Templates\AzureRGDeploy.json. Wildcards like \*\*\\\*.json or \*\*\\*.param.json are also supported and there needs to be only one file that matches the search pattern at the location. If more than one file matches the search pattern, then the task will error out. From 503a5927b0c8d09f7946aee4ac64e5ff00ef7694 Mon Sep 17 00:00:00 2001 From: t-dedah Date: Tue, 18 Jan 2022 04:49:00 +0530 Subject: [PATCH 08/19] Updated createOrUpdate.ts --- .../Tests/createOrUpdate.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/createOrUpdate.ts b/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/createOrUpdate.ts index b2f153b8a041..925eca8d479d 100644 --- a/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/createOrUpdate.ts +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/createOrUpdate.ts @@ -28,6 +28,7 @@ process.env["ENDPOINT_DATA_AzureRM_ENVIRONMENTAUTHORITYURL"] = "https://login.wi process.env["ENDPOINT_DATA_AzureRM_ACTIVEDIRECTORYSERVICEENDPOINTRESOURCEID"] = "https://management.azure.com"; var CSMJson = path.join(__dirname, "CSM.json"); +var CSMBicep = path.join(__dirname, "CSM.bicep"); var CSMwithComments = path.join(__dirname, "CSMwithComments.json"); var defaults = path.join(__dirname, "defaults.json"); var faultyCSM = path.join(__dirname, "faultyCSM.json"); @@ -35,6 +36,7 @@ var faultyCSM = path.join(__dirname, "faultyCSM.json"); let a: ma.TaskLibAnswers = { "findMatch": { "CSM.json": [CSMJson], + "CSM.bicep": [CSMBicep], "CSMwithComments.json": [CSMwithComments], "defaults.json": [defaults], "faultyCSM.json": [faultyCSM], From 8dcac5c0c76ba1e4930fa8c3ec1c2aab7c027d05 Mon Sep 17 00:00:00 2001 From: t-dedah Date: Tue, 18 Jan 2022 05:04:09 +0530 Subject: [PATCH 09/19] minor changes --- .../Tests/{CSM.bicep => CSMwithBicep.bicep} | 0 Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts | 2 +- .../Tests/createOrUpdate.ts | 4 ++-- 3 files changed, 3 insertions(+), 3 deletions(-) rename Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/{CSM.bicep => CSMwithBicep.bicep} (100%) diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/CSM.bicep b/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/CSMwithBicep.bicep similarity index 100% rename from Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/CSM.bicep rename to Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/CSMwithBicep.bicep diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts b/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts index 88cdffae01ac..b3346ea716b0 100644 --- a/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts @@ -175,7 +175,7 @@ describe('Azure Resource Manager Template Deployment', function () { it('Successfully triggered createOrUpdate deployment using bicep file', (done) => { let tp = path.join(__dirname, 'createOrUpdate.js'); - process.env["csmFile"] = "CSM.bicep"; + process.env["csmFile"] = "CSMwithBicep.bicep"; process.env["deploymentOutputs"] = "someVar"; let tr = new ttm.MockTestRunner(tp); tr.run(); diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/createOrUpdate.ts b/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/createOrUpdate.ts index 925eca8d479d..467c434fee86 100644 --- a/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/createOrUpdate.ts +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/createOrUpdate.ts @@ -28,7 +28,7 @@ process.env["ENDPOINT_DATA_AzureRM_ENVIRONMENTAUTHORITYURL"] = "https://login.wi process.env["ENDPOINT_DATA_AzureRM_ACTIVEDIRECTORYSERVICEENDPOINTRESOURCEID"] = "https://management.azure.com"; var CSMJson = path.join(__dirname, "CSM.json"); -var CSMBicep = path.join(__dirname, "CSM.bicep"); +var CSMBicep = path.join(__dirname, "CSMwithBicep.bicep"); var CSMwithComments = path.join(__dirname, "CSMwithComments.json"); var defaults = path.join(__dirname, "defaults.json"); var faultyCSM = path.join(__dirname, "faultyCSM.json"); @@ -36,7 +36,7 @@ var faultyCSM = path.join(__dirname, "faultyCSM.json"); let a: ma.TaskLibAnswers = { "findMatch": { "CSM.json": [CSMJson], - "CSM.bicep": [CSMBicep], + "CSMwithBicep.bicep": [CSMBicep], "CSMwithComments.json": [CSMwithComments], "defaults.json": [defaults], "faultyCSM.json": [faultyCSM], From 6231a50abd58299a852005175bf6ffcc03782b2d Mon Sep 17 00:00:00 2001 From: t-dedah Date: Tue, 18 Jan 2022 05:12:38 +0530 Subject: [PATCH 10/19] Testing --- Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts b/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts index b3346ea716b0..1569ee3cd532 100644 --- a/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts @@ -176,6 +176,7 @@ describe('Azure Resource Manager Template Deployment', function () { it('Successfully triggered createOrUpdate deployment using bicep file', (done) => { let tp = path.join(__dirname, 'createOrUpdate.js'); process.env["csmFile"] = "CSMwithBicep.bicep"; + process.env["csmParametersFile"] = ""; process.env["deploymentOutputs"] = "someVar"; let tr = new ttm.MockTestRunner(tp); tr.run(); From 7a55cc6c3a72f7a97bf56d02401b57633dc4fce3 Mon Sep 17 00:00:00 2001 From: t-dedah Date: Tue, 18 Jan 2022 05:15:34 +0530 Subject: [PATCH 11/19] Removed parameter test --- Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts b/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts index 1569ee3cd532..6fcac1a4da66 100644 --- a/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts @@ -182,7 +182,6 @@ describe('Azure Resource Manager Template Deployment', function () { tr.run(); try { assert(tr.succeeded, "Should have succeeded"); - assert(tr.stdout.indexOf("properly sanitized") > 0, "Parameters should have been sanitized"); assert(tr.stdout.indexOf("deployments.createOrUpdate is called") > 0, "deployments.createOrUpdate function should have been called from azure-sdk"); assert(tr.stdout.indexOf("##vso[task.setvariable variable=someVar;]") >= 0, "deploymentsOutput should have been updated"); done(); From 690bb249c01b9eb71966c90d0f05d8249eff7220 Mon Sep 17 00:00:00 2001 From: t-dedah Date: Tue, 18 Jan 2022 23:03:45 +0530 Subject: [PATCH 12/19] Version issue resolved --- .../operations/Utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/operations/Utils.ts b/Tasks/AzureResourceManagerTemplateDeploymentV3/operations/Utils.ts index 0db4272f9efc..4d760889c935 100644 --- a/Tasks/AzureResourceManagerTemplateDeploymentV3/operations/Utils.ts +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/operations/Utils.ts @@ -473,7 +473,7 @@ class Utils { let majorVersion = azcliversion.split('.')[0] let minorVersion = azcliversion.split('.')[1] // Support Bicep was introduced in az-cli 2.20.0 - if(majorVersion >= 2 && minorVersion >= 20){ + if((majorVersion == 2 && minorVersion >= 20) || majorVersion > 2){ return true } return false From eb8637783b10f180b246551d9f4f7940de41ef42 Mon Sep 17 00:00:00 2001 From: t-dedah Date: Tue, 25 Jan 2022 02:56:30 +0530 Subject: [PATCH 13/19] Updated bicepBuild --- .../operations/Utils.ts | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/operations/Utils.ts b/Tasks/AzureResourceManagerTemplateDeploymentV3/operations/Utils.ts index 4d760889c935..b8203f12097f 100644 --- a/Tasks/AzureResourceManagerTemplateDeploymentV3/operations/Utils.ts +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/operations/Utils.ts @@ -444,28 +444,23 @@ class Utils { private static async getAzureCliVersion(): Promise { let azcliversion: string = "" ; - try { - const { stdout, stderr } = await cpExec('az version'); - if (!stderr) { + const {error, stdout, stderr } = await cpExec('az version'); + if(error && error.code !== 0){ + throw new Error(tl.loc("FailedToFetchAzureCLIVersion", stderr)); + }else{ + try{ azcliversion = JSON.parse(stdout)["azure-cli"] - } else { - throw stderr + }catch(err){ + throw new Error(tl.loc("FailedToFetchAzureCLIVersion", err)); } - } catch (err) { - throw new Error(tl.loc("FailedToFetchAzureCLIVersion", err)); } return azcliversion } private static async execBicepBuild(filePath): Promise { - try { - const { stdout, stderr } = await cpExec(`az bicep build --file ${filePath}`); - if (!stderr) { - } else { - throw stderr - } - } catch (err) { - throw new Error(tl.loc("BicepBuildFailed", err)); + const {error, stdout, stderr} = await cpExec(`az bicep build --file ${filePath}`); + if(error && error.code !== 0){ + throw new Error(tl.loc("BicepBuildFailed", stderr)); } } From 9d35afbb4bc43457d54b0abd8c14a9b8bd0f997c Mon Sep 17 00:00:00 2001 From: Apple Date: Tue, 25 Jan 2022 03:28:57 +0530 Subject: [PATCH 14/19] Added more tests --- .../Tests/CSMwithBicepWithWarning.bicep | 19 +++++++++++++++++++ .../Tests/L0.ts | 19 +++++++++++++++++++ .../Tests/createOrUpdate.ts | 2 ++ 3 files changed, 40 insertions(+) create mode 100644 Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/CSMwithBicepWithWarning.bicep diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/CSMwithBicepWithWarning.bicep b/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/CSMwithBicepWithWarning.bicep new file mode 100644 index 000000000000..ee96f96d64bf --- /dev/null +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/CSMwithBicepWithWarning.bicep @@ -0,0 +1,19 @@ +param location string = 'eastasia' +param unusedParam string = 'test' + +var storageAccountName_var = 'deepak2121' +var storageAccountType = 'Premium_LRS' + +resource storageAccount 'Microsoft.Storage/storageAccounts@2021-01-01' = { + name: toLower(take(storageAccountName_var, 24)) + location: location + sku: { + name: storageAccountType + } + kind: 'StorageV2' +} + +output storageAccount_Name string = storageAccount.name +output storageAccount_Location string = storageAccount.location +output storageAccount_SKUName string = storageAccount.sku.name +output storageAccount_Kind string = storageAccount.kind \ No newline at end of file diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts b/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts index 6fcac1a4da66..dab696e12e2f 100644 --- a/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts @@ -192,4 +192,23 @@ describe('Azure Resource Manager Template Deployment', function () { done(error); } }); + + it('Successfully triggered createOrUpdate deployment using bicep file with unused params', (done) => { + let tp = path.join(__dirname, 'createOrUpdate.js'); + process.env["csmFile"] = "CSMwithBicepWithWarning.bicep"; + process.env["csmParametersFile"] = ""; + process.env["deploymentOutputs"] = "someVar"; + let tr = new ttm.MockTestRunner(tp); + tr.run(); + try { + assert(tr.succeeded, "Should have succeeded"); + assert(tr.stdout.indexOf("##vso[task.setvariable variable=someVar;]") >= 0, "deploymentsOutput should have been updated"); + done(); + } + catch (error) { + console.log("STDERR", tr.stderr); + console.log("STDOUT", tr.stdout); + done(error); + } + }); }); diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/createOrUpdate.ts b/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/createOrUpdate.ts index 467c434fee86..783062273735 100644 --- a/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/createOrUpdate.ts +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/createOrUpdate.ts @@ -29,6 +29,7 @@ process.env["ENDPOINT_DATA_AzureRM_ACTIVEDIRECTORYSERVICEENDPOINTRESOURCEID"] = var CSMJson = path.join(__dirname, "CSM.json"); var CSMBicep = path.join(__dirname, "CSMwithBicep.bicep"); +var CSMBicepWithWarning = path.join(__dirname, "CSMwithBicepWithWarning.bicep"); var CSMwithComments = path.join(__dirname, "CSMwithComments.json"); var defaults = path.join(__dirname, "defaults.json"); var faultyCSM = path.join(__dirname, "faultyCSM.json"); @@ -37,6 +38,7 @@ let a: ma.TaskLibAnswers = { "findMatch": { "CSM.json": [CSMJson], "CSMwithBicep.bicep": [CSMBicep], + "CSMwithBicepWithWarning.bicep": [CSMBicepWithWarning], "CSMwithComments.json": [CSMwithComments], "defaults.json": [defaults], "faultyCSM.json": [faultyCSM], From ab96c40645b2cd4f4142a80bb7ffb119ae2a66f6 Mon Sep 17 00:00:00 2001 From: Apple Date: Tue, 25 Jan 2022 03:56:33 +0530 Subject: [PATCH 15/19] Added negative test --- .../Tests/CSMwithBicepWithError.bicep | 20 ++++++++++++++++++ .../Tests/L0.ts | 21 +++++++++++++++++++ .../Tests/createOrUpdate.ts | 2 ++ 3 files changed, 43 insertions(+) create mode 100644 Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/CSMwithBicepWithError.bicep diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/CSMwithBicepWithError.bicep b/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/CSMwithBicepWithError.bicep new file mode 100644 index 000000000000..f11f9841591b --- /dev/null +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/CSMwithBicepWithError.bicep @@ -0,0 +1,20 @@ +param location string = 'eastasia' + +var storageAccountName_var = 'deepak2121' +var storageAccountType = 'Premium_LRS' + +randomstring + +resource storageAccount 'Microsoft.Storage/storageAccounts@2021-01-01' = { + name: toLower(take(storageAccountName_var, 24)) + location: location + sku: { + name: storageAccountType + } + kind: 'StorageV2' +} + +output storageAccount_Name string = storageAccount.name +output storageAccount_Location string = storageAccount.location +output storageAccount_SKUName string = storageAccount.sku.name +output storageAccount_Kind string = storageAccount.kind \ No newline at end of file diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts b/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts index dab696e12e2f..12fa75e73eed 100644 --- a/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts @@ -202,6 +202,7 @@ describe('Azure Resource Manager Template Deployment', function () { tr.run(); try { assert(tr.succeeded, "Should have succeeded"); + assert(tr.stdout.indexOf("deployments.createOrUpdate is called") > 0, "deployments.createOrUpdate function should have been called from azure-sdk"); assert(tr.stdout.indexOf("##vso[task.setvariable variable=someVar;]") >= 0, "deploymentsOutput should have been updated"); done(); } @@ -211,4 +212,24 @@ describe('Azure Resource Manager Template Deployment', function () { done(error); } }); + + it('createOrUpdate deployment should fail when bicep file contains error', (done) => { + let tp = path.join(__dirname, 'createOrUpdate.js'); + process.env["csmFile"] = "CSMwithBicepWithError.json"; + process.env["csmParametersFile"] = ""; + let tr = new ttm.MockTestRunner(tp); + tr.run(); + try { + assert(!tr.succeeded, "Should have failed"); + assert(tr.stdout.indexOf("BicepBuildFailed") > 0, "should have printed BicepBuildFailed") + assert(tr.stdout.indexOf("This declaration type is not recognized. Specify a parameter, variable, resource, or output declaration.") > 0, "should have printed the error message") + assert(tr.stdout.indexOf("deployments.createOrUpdate is called") < 0, "deployments.createOrUpdate function should not have been called from azure-sdk"); + done(); + } + catch (error) { + console.log("STDERR", tr.stderr); + console.log("STDOUT", tr.stdout); + done(error); + } + }); }); diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/createOrUpdate.ts b/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/createOrUpdate.ts index 783062273735..19a639387daa 100644 --- a/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/createOrUpdate.ts +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/createOrUpdate.ts @@ -30,6 +30,7 @@ process.env["ENDPOINT_DATA_AzureRM_ACTIVEDIRECTORYSERVICEENDPOINTRESOURCEID"] = var CSMJson = path.join(__dirname, "CSM.json"); var CSMBicep = path.join(__dirname, "CSMwithBicep.bicep"); var CSMBicepWithWarning = path.join(__dirname, "CSMwithBicepWithWarning.bicep"); +var CSMBicepWithError = path.join(__dirname, "CSMwithBicepWithError.bicep"); var CSMwithComments = path.join(__dirname, "CSMwithComments.json"); var defaults = path.join(__dirname, "defaults.json"); var faultyCSM = path.join(__dirname, "faultyCSM.json"); @@ -39,6 +40,7 @@ let a: ma.TaskLibAnswers = { "CSM.json": [CSMJson], "CSMwithBicep.bicep": [CSMBicep], "CSMwithBicepWithWarning.bicep": [CSMBicepWithWarning], + "CSMwithBicepWithError.bicep": [CSMBicepWithError], "CSMwithComments.json": [CSMwithComments], "defaults.json": [defaults], "faultyCSM.json": [faultyCSM], From 2f8dee612b63e1ade366f2bd2a91b99debc4972f Mon Sep 17 00:00:00 2001 From: Apple Date: Tue, 25 Jan 2022 04:04:12 +0530 Subject: [PATCH 16/19] Testing output --- Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts b/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts index 12fa75e73eed..f8da4489d7a7 100644 --- a/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts @@ -219,6 +219,10 @@ describe('Azure Resource Manager Template Deployment', function () { process.env["csmParametersFile"] = ""; let tr = new ttm.MockTestRunner(tp); tr.run(); + + console.log(tr.stdout) + + try { assert(!tr.succeeded, "Should have failed"); assert(tr.stdout.indexOf("BicepBuildFailed") > 0, "should have printed BicepBuildFailed") From a4031b34e52598918cd2c66ad01aca965af6d683 Mon Sep 17 00:00:00 2001 From: Apple Date: Tue, 25 Jan 2022 04:09:12 +0530 Subject: [PATCH 17/19] Resolved test issue --- Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts b/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts index f8da4489d7a7..c5f02343d6ef 100644 --- a/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts @@ -219,14 +219,9 @@ describe('Azure Resource Manager Template Deployment', function () { process.env["csmParametersFile"] = ""; let tr = new ttm.MockTestRunner(tp); tr.run(); - - console.log(tr.stdout) - - try { assert(!tr.succeeded, "Should have failed"); assert(tr.stdout.indexOf("BicepBuildFailed") > 0, "should have printed BicepBuildFailed") - assert(tr.stdout.indexOf("This declaration type is not recognized. Specify a parameter, variable, resource, or output declaration.") > 0, "should have printed the error message") assert(tr.stdout.indexOf("deployments.createOrUpdate is called") < 0, "deployments.createOrUpdate function should not have been called from azure-sdk"); done(); } From 640864ffe4063c3c60afd9daac6c630dcafb8cba Mon Sep 17 00:00:00 2001 From: Apple Date: Tue, 25 Jan 2022 04:15:10 +0530 Subject: [PATCH 18/19] json to bicep bug --- Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts b/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts index c5f02343d6ef..da07a6150e8a 100644 --- a/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts @@ -215,13 +215,14 @@ describe('Azure Resource Manager Template Deployment', function () { it('createOrUpdate deployment should fail when bicep file contains error', (done) => { let tp = path.join(__dirname, 'createOrUpdate.js'); - process.env["csmFile"] = "CSMwithBicepWithError.json"; + process.env["csmFile"] = "CSMwithBicepWithError.bicep"; process.env["csmParametersFile"] = ""; let tr = new ttm.MockTestRunner(tp); tr.run(); try { assert(!tr.succeeded, "Should have failed"); assert(tr.stdout.indexOf("BicepBuildFailed") > 0, "should have printed BicepBuildFailed") + assert(tr.stdout.indexOf("This declaration type is not recognized. Specify a parameter, variable, resource, or output declaration.") > 0, "should have printed the error message") assert(tr.stdout.indexOf("deployments.createOrUpdate is called") < 0, "deployments.createOrUpdate function should not have been called from azure-sdk"); done(); } From 14a1971c09eb9a85127f7a3f2290ff656ea84982 Mon Sep 17 00:00:00 2001 From: Apple Date: Tue, 25 Jan 2022 04:21:42 +0530 Subject: [PATCH 19/19] bicep build fail test --- Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts b/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts index da07a6150e8a..98eefaeb0d00 100644 --- a/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts @@ -221,7 +221,6 @@ describe('Azure Resource Manager Template Deployment', function () { tr.run(); try { assert(!tr.succeeded, "Should have failed"); - assert(tr.stdout.indexOf("BicepBuildFailed") > 0, "should have printed BicepBuildFailed") assert(tr.stdout.indexOf("This declaration type is not recognized. Specify a parameter, variable, resource, or output declaration.") > 0, "should have printed the error message") assert(tr.stdout.indexOf("deployments.createOrUpdate is called") < 0, "deployments.createOrUpdate function should not have been called from azure-sdk"); done();