Skip to content

Commit 67e1fd6

Browse files
fix for bicep param file with multiple extensions (#19581)
Co-authored-by: Steven Cady <[email protected]> Co-authored-by: Mohith <[email protected]>
1 parent 37c49cf commit 67e1fd6

File tree

19 files changed

+136
-31
lines changed

19 files changed

+136
-31
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
using 'CSMwithBicep.bicep'
2+
3+
param location = 'eastasia'

Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts

+20
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,26 @@ describe('Azure Resource Manager Template Deployment', function () {
246246
}
247247
});
248248

249+
it('Successfully triggered createOrUpdate deployment using bicep file with bicepparam file using multiple file extensions', (done) => {
250+
let tp = path.join(__dirname, 'createOrUpdate.js');
251+
process.env["csmFile"] = "CSMwithBicep.bicep";
252+
process.env["csmParametersFile"] = "CSMwithBicep.prod.bicepparam";
253+
process.env["deploymentOutputs"] = "someVar";
254+
let tr = new ttm.MockTestRunner(tp);
255+
tr.run();
256+
try {
257+
assert(tr.succeeded, "Should have succeeded");
258+
assert(tr.stdout.indexOf("deployments.createOrUpdate is called") > 0, "deployments.createOrUpdate function should have been called from azure-sdk");
259+
assert(tr.stdout.indexOf("##vso[task.setvariable variable=someVar;]") >= 0, "deploymentsOutput should have been updated");
260+
done();
261+
}
262+
catch (error) {
263+
console.log("STDERR", tr.stderr);
264+
console.log("STDOUT", tr.stdout);
265+
done(error);
266+
}
267+
});
268+
249269
// it('createOrUpdate deployment should fail when bicep file contains error', (done) => {
250270
// let tp = path.join(__dirname, 'createOrUpdate.js');
251271
// process.env["csmFile"] = "CSMwithBicepWithError.bicep";

Tasks/AzureResourceManagerTemplateDeploymentV3/Tests/createOrUpdate.ts

+4
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@ process.env["ENDPOINT_AUTH_PARAMETER_AzureRM_AUTHENTICATIONTYPE"] = "key";
3434
var CSMJson = path.join(__dirname, "CSM.json");
3535
var CSMBicep = path.join(__dirname, "CSMwithBicep.bicep");
3636
var CSMBicepParam = path.join(__dirname, "CSMwithBicep.bicepparam");
37+
var CSMBicepParamWithEnv = path.join(__dirname, "CSMwithBicep.prod.bicepparam");
3738
var CSMBicepWithWarning = path.join(__dirname, "CSMwithBicepWithWarning.bicep");
3839
var CSMBicepWithError = path.join(__dirname, "CSMwithBicepWithError.bicep");
3940
var CSMwithComments = path.join(__dirname, "CSMwithComments.json");
4041
var defaults = path.join(__dirname, "defaults.json");
4142
var faultyCSM = path.join(__dirname, "faultyCSM.json");
4243
var bicepbuildCmd = `az bicep build --file ${path.join(__dirname, "CSMwithBicep.bicep")}`;
4344
var bicepparambuildCmd = `az bicep build-params --file ${path.join(__dirname, "CSMwithBicep.bicepparam")} --outfile ${path.join(__dirname, "CSMwithBicep.parameters.json")}`;
45+
var bicepparambuildwithenvironmentCmd = `az bicep build-params --file ${path.join(__dirname, "CSMwithBicep.prod.bicepparam")} --outfile ${path.join(__dirname, "CSMwithBicep.parameters.json")}`;
4446
var bicepbuildwithWarning = `az bicep build --file ${path.join(__dirname, "CSMwithBicepWithWarning.bicep")}`;
4547
var azloginCommand = `az login --service-principal -u "id" --password="key" --tenant "tenant" --allow-no-subscriptions`;
4648
var azaccountSet = `az account set --subscription "sId"`;
@@ -53,6 +55,7 @@ const successExec = {
5355
}
5456
exec[bicepbuildCmd] = successExec;
5557
exec[bicepparambuildCmd] = successExec;
58+
exec[bicepparambuildwithenvironmentCmd] = successExec;
5659
exec[bicepbuildwithWarning] = successExec;
5760
exec[azloginCommand] = successExec;
5861
exec[azaccountSet] = successExec;
@@ -70,6 +73,7 @@ let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
7073
"CSM.json": [CSMJson],
7174
"CSMwithBicep.bicep": [CSMBicep],
7275
"CSMwithBicep.bicepparam": [CSMBicepParam],
76+
"CSMwithBicep.prod.bicepparam": [CSMBicepParamWithEnv],
7377
"CSMwithBicepWithWarning.bicep": [CSMBicepWithWarning],
7478
"CSMwithBicepWithError.bicep": [CSMBicepWithError],
7579
"CSMwithComments.json": [CSMwithComments],

Tasks/AzureResourceManagerTemplateDeploymentV3/operations/Utils.ts

+13-5
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,14 @@ class Utils {
438438
filePath = filePath.replace('.bicep', '.json')
439439
}
440440
else{
441-
filePath = filePath.replace('.bicepparam', '.parameters.json')
441+
var fullFileName: string = filePath.split(path.sep).pop()
442+
var bicepParamExtension: string = '.bicepparam'
443+
if(fullFileName.split('.').length > 2){
444+
var nameArray: Array<string> = fullFileName.split('.')
445+
nameArray.splice(0, 1)
446+
bicepParamExtension = '.'+nameArray.join('.')
447+
}
448+
filePath = filePath.replace(bicepParamExtension, '.parameters.json')
442449
}
443450
await this.logoutAzure();
444451
}else{
@@ -474,18 +481,19 @@ class Utils {
474481
}
475482

476483
private static async execBicepBuild(filePath): Promise<void> {
484+
var fullFileName: string = filePath.split(path.sep).pop()
485+
var fileDir: string = filePath.replace(path.sep + fullFileName, '')
477486
var filePathExtension: string = filePath.split('.').pop();
487+
var fileName: string = filePath.split(path.sep).pop().split('.')[0];
478488
var finalPathExtension: string = ".json"
479-
489+
480490
if(filePathExtension === 'bicep'){
481491
const result: IExecSyncResult = tl.execSync("az", `bicep build --file ${filePath}`);
482492
if(result && result.code !== 0){
483493
throw new Error(tl.loc("BicepBuildFailed", result.stderr));
484494
}
485495
}
486496
else{
487-
var fileName: string = filePath.split(path.sep).pop().split('.')[0];
488-
var fileDir: string = filePath.replace(path.sep + fileName +'.bicepparam', '')
489497
finalPathExtension = ".parameters.json"
490498

491499
//Using --outfile to avoid overwriting primary bicep file in the case bicep and param file have the the same file name.
@@ -495,7 +503,7 @@ class Utils {
495503
}
496504
}
497505

498-
this.cleanupFileList.push(filePath.replace('.' + filePathExtension, finalPathExtension))
506+
this.cleanupFileList.push(fileDir + path.sep + fileName + finalPathExtension)
499507
}
500508

501509
private static async logoutAzure() {

Tasks/AzureResourceManagerTemplateDeploymentV3/task.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"author": "Microsoft Corporation",
1515
"version": {
1616
"Major": 3,
17-
"Minor": 235,
17+
"Minor": 236,
1818
"Patch": 0
1919
},
2020
"demands": [],

Tasks/AzureResourceManagerTemplateDeploymentV3/task.loc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"author": "Microsoft Corporation",
1515
"version": {
1616
"Major": 3,
17-
"Minor": 235,
17+
"Minor": 236,
1818
"Patch": 0
1919
},
2020
"demands": [],
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Default|3.235.0
2-
Node20_229_2|3.235.1
1+
Default|3.236.0
2+
Node20_229_2|3.236.1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
using 'CSMwithBicep.bicep'
2+
3+
param location = 'eastasia'

_generated/AzureResourceManagerTemplateDeploymentV3/Tests/L0.ts

+20
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,26 @@ describe('Azure Resource Manager Template Deployment', function () {
246246
}
247247
});
248248

249+
it('Successfully triggered createOrUpdate deployment using bicep file with bicepparam file using multiple file extensions', (done) => {
250+
let tp = path.join(__dirname, 'createOrUpdate.js');
251+
process.env["csmFile"] = "CSMwithBicep.bicep";
252+
process.env["csmParametersFile"] = "CSMwithBicep.prod.bicepparam";
253+
process.env["deploymentOutputs"] = "someVar";
254+
let tr = new ttm.MockTestRunner(tp);
255+
tr.run();
256+
try {
257+
assert(tr.succeeded, "Should have succeeded");
258+
assert(tr.stdout.indexOf("deployments.createOrUpdate is called") > 0, "deployments.createOrUpdate function should have been called from azure-sdk");
259+
assert(tr.stdout.indexOf("##vso[task.setvariable variable=someVar;]") >= 0, "deploymentsOutput should have been updated");
260+
done();
261+
}
262+
catch (error) {
263+
console.log("STDERR", tr.stderr);
264+
console.log("STDOUT", tr.stdout);
265+
done(error);
266+
}
267+
});
268+
249269
// it('createOrUpdate deployment should fail when bicep file contains error', (done) => {
250270
// let tp = path.join(__dirname, 'createOrUpdate.js');
251271
// process.env["csmFile"] = "CSMwithBicepWithError.bicep";

_generated/AzureResourceManagerTemplateDeploymentV3/Tests/createOrUpdate.ts

+4
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@ process.env["ENDPOINT_AUTH_PARAMETER_AzureRM_AUTHENTICATIONTYPE"] = "key";
3434
var CSMJson = path.join(__dirname, "CSM.json");
3535
var CSMBicep = path.join(__dirname, "CSMwithBicep.bicep");
3636
var CSMBicepParam = path.join(__dirname, "CSMwithBicep.bicepparam");
37+
var CSMBicepParamWithEnv = path.join(__dirname, "CSMwithBicep.prod.bicepparam");
3738
var CSMBicepWithWarning = path.join(__dirname, "CSMwithBicepWithWarning.bicep");
3839
var CSMBicepWithError = path.join(__dirname, "CSMwithBicepWithError.bicep");
3940
var CSMwithComments = path.join(__dirname, "CSMwithComments.json");
4041
var defaults = path.join(__dirname, "defaults.json");
4142
var faultyCSM = path.join(__dirname, "faultyCSM.json");
4243
var bicepbuildCmd = `az bicep build --file ${path.join(__dirname, "CSMwithBicep.bicep")}`;
4344
var bicepparambuildCmd = `az bicep build-params --file ${path.join(__dirname, "CSMwithBicep.bicepparam")} --outfile ${path.join(__dirname, "CSMwithBicep.parameters.json")}`;
45+
var bicepparambuildwithenvironmentCmd = `az bicep build-params --file ${path.join(__dirname, "CSMwithBicep.prod.bicepparam")} --outfile ${path.join(__dirname, "CSMwithBicep.parameters.json")}`;
4446
var bicepbuildwithWarning = `az bicep build --file ${path.join(__dirname, "CSMwithBicepWithWarning.bicep")}`;
4547
var azloginCommand = `az login --service-principal -u "id" --password="key" --tenant "tenant" --allow-no-subscriptions`;
4648
var azaccountSet = `az account set --subscription "sId"`;
@@ -53,6 +55,7 @@ const successExec = {
5355
}
5456
exec[bicepbuildCmd] = successExec;
5557
exec[bicepparambuildCmd] = successExec;
58+
exec[bicepparambuildwithenvironmentCmd] = successExec;
5659
exec[bicepbuildwithWarning] = successExec;
5760
exec[azloginCommand] = successExec;
5861
exec[azaccountSet] = successExec;
@@ -70,6 +73,7 @@ let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
7073
"CSM.json": [CSMJson],
7174
"CSMwithBicep.bicep": [CSMBicep],
7275
"CSMwithBicep.bicepparam": [CSMBicepParam],
76+
"CSMwithBicep.prod.bicepparam": [CSMBicepParamWithEnv],
7377
"CSMwithBicepWithWarning.bicep": [CSMBicepWithWarning],
7478
"CSMwithBicepWithError.bicep": [CSMBicepWithError],
7579
"CSMwithComments.json": [CSMwithComments],

_generated/AzureResourceManagerTemplateDeploymentV3/operations/Utils.ts

+13-5
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,14 @@ class Utils {
438438
filePath = filePath.replace('.bicep', '.json')
439439
}
440440
else{
441-
filePath = filePath.replace('.bicepparam', '.parameters.json')
441+
var fullFileName: string = filePath.split(path.sep).pop()
442+
var bicepParamExtension: string = '.bicepparam'
443+
if(fullFileName.split('.').length > 2){
444+
var nameArray: Array<string> = fullFileName.split('.')
445+
nameArray.splice(0, 1)
446+
bicepParamExtension = '.'+nameArray.join('.')
447+
}
448+
filePath = filePath.replace(bicepParamExtension, '.parameters.json')
442449
}
443450
await this.logoutAzure();
444451
}else{
@@ -474,18 +481,19 @@ class Utils {
474481
}
475482

476483
private static async execBicepBuild(filePath): Promise<void> {
484+
var fullFileName: string = filePath.split(path.sep).pop()
485+
var fileDir: string = filePath.replace(path.sep + fullFileName, '')
477486
var filePathExtension: string = filePath.split('.').pop();
487+
var fileName: string = filePath.split(path.sep).pop().split('.')[0];
478488
var finalPathExtension: string = ".json"
479-
489+
480490
if(filePathExtension === 'bicep'){
481491
const result: IExecSyncResult = tl.execSync("az", `bicep build --file ${filePath}`);
482492
if(result && result.code !== 0){
483493
throw new Error(tl.loc("BicepBuildFailed", result.stderr));
484494
}
485495
}
486496
else{
487-
var fileName: string = filePath.split(path.sep).pop().split('.')[0];
488-
var fileDir: string = filePath.replace(path.sep + fileName +'.bicepparam', '')
489497
finalPathExtension = ".parameters.json"
490498

491499
//Using --outfile to avoid overwriting primary bicep file in the case bicep and param file have the the same file name.
@@ -495,7 +503,7 @@ class Utils {
495503
}
496504
}
497505

498-
this.cleanupFileList.push(filePath.replace('.' + filePathExtension, finalPathExtension))
506+
this.cleanupFileList.push(fileDir + path.sep + fileName + finalPathExtension)
499507
}
500508

501509
private static async logoutAzure() {

_generated/AzureResourceManagerTemplateDeploymentV3/task.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"author": "Microsoft Corporation",
1515
"version": {
1616
"Major": 3,
17-
"Minor": 235,
17+
"Minor": 236,
1818
"Patch": 0
1919
},
2020
"demands": [],
@@ -336,7 +336,7 @@
336336
"IncompatibleAzureCLIVersionBicepParam": "Azure CLI version should be >= 2.47.0 to use .bicepparam file"
337337
},
338338
"_buildConfigMapping": {
339-
"Default": "3.235.0",
340-
"Node20_229_2": "3.235.1"
339+
"Default": "3.236.0",
340+
"Node20_229_2": "3.236.1"
341341
}
342342
}

_generated/AzureResourceManagerTemplateDeploymentV3/task.loc.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"author": "Microsoft Corporation",
1515
"version": {
1616
"Major": 3,
17-
"Minor": 235,
17+
"Minor": 236,
1818
"Patch": 0
1919
},
2020
"demands": [],
@@ -336,7 +336,7 @@
336336
"IncompatibleAzureCLIVersionBicepParam": "ms-resource:loc.messages.IncompatibleAzureCLIVersionBicepParam"
337337
},
338338
"_buildConfigMapping": {
339-
"Default": "3.235.0",
340-
"Node20_229_2": "3.235.1"
339+
"Default": "3.236.0",
340+
"Node20_229_2": "3.236.1"
341341
}
342342
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
using 'CSMwithBicep.bicep'
2+
3+
param location = 'eastasia'

_generated/AzureResourceManagerTemplateDeploymentV3_Node20/Tests/L0.ts

+20
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,26 @@ describe('Azure Resource Manager Template Deployment', function () {
246246
}
247247
});
248248

249+
it('Successfully triggered createOrUpdate deployment using bicep file with bicepparam file using multiple file extensions', (done) => {
250+
let tp = path.join(__dirname, 'createOrUpdate.js');
251+
process.env["csmFile"] = "CSMwithBicep.bicep";
252+
process.env["csmParametersFile"] = "CSMwithBicep.prod.bicepparam";
253+
process.env["deploymentOutputs"] = "someVar";
254+
let tr = new ttm.MockTestRunner(tp);
255+
tr.run();
256+
try {
257+
assert(tr.succeeded, "Should have succeeded");
258+
assert(tr.stdout.indexOf("deployments.createOrUpdate is called") > 0, "deployments.createOrUpdate function should have been called from azure-sdk");
259+
assert(tr.stdout.indexOf("##vso[task.setvariable variable=someVar;]") >= 0, "deploymentsOutput should have been updated");
260+
done();
261+
}
262+
catch (error) {
263+
console.log("STDERR", tr.stderr);
264+
console.log("STDOUT", tr.stdout);
265+
done(error);
266+
}
267+
});
268+
249269
// it('createOrUpdate deployment should fail when bicep file contains error', (done) => {
250270
// let tp = path.join(__dirname, 'createOrUpdate.js');
251271
// process.env["csmFile"] = "CSMwithBicepWithError.bicep";

_generated/AzureResourceManagerTemplateDeploymentV3_Node20/Tests/createOrUpdate.ts

+4
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@ process.env["ENDPOINT_AUTH_PARAMETER_AzureRM_AUTHENTICATIONTYPE"] = "key";
3434
var CSMJson = path.join(__dirname, "CSM.json");
3535
var CSMBicep = path.join(__dirname, "CSMwithBicep.bicep");
3636
var CSMBicepParam = path.join(__dirname, "CSMwithBicep.bicepparam");
37+
var CSMBicepParamWithEnv = path.join(__dirname, "CSMwithBicep.prod.bicepparam");
3738
var CSMBicepWithWarning = path.join(__dirname, "CSMwithBicepWithWarning.bicep");
3839
var CSMBicepWithError = path.join(__dirname, "CSMwithBicepWithError.bicep");
3940
var CSMwithComments = path.join(__dirname, "CSMwithComments.json");
4041
var defaults = path.join(__dirname, "defaults.json");
4142
var faultyCSM = path.join(__dirname, "faultyCSM.json");
4243
var bicepbuildCmd = `az bicep build --file ${path.join(__dirname, "CSMwithBicep.bicep")}`;
4344
var bicepparambuildCmd = `az bicep build-params --file ${path.join(__dirname, "CSMwithBicep.bicepparam")} --outfile ${path.join(__dirname, "CSMwithBicep.parameters.json")}`;
45+
var bicepparambuildwithenvironmentCmd = `az bicep build-params --file ${path.join(__dirname, "CSMwithBicep.prod.bicepparam")} --outfile ${path.join(__dirname, "CSMwithBicep.parameters.json")}`;
4446
var bicepbuildwithWarning = `az bicep build --file ${path.join(__dirname, "CSMwithBicepWithWarning.bicep")}`;
4547
var azloginCommand = `az login --service-principal -u "id" --password="key" --tenant "tenant" --allow-no-subscriptions`;
4648
var azaccountSet = `az account set --subscription "sId"`;
@@ -53,6 +55,7 @@ const successExec = {
5355
}
5456
exec[bicepbuildCmd] = successExec;
5557
exec[bicepparambuildCmd] = successExec;
58+
exec[bicepparambuildwithenvironmentCmd] = successExec;
5659
exec[bicepbuildwithWarning] = successExec;
5760
exec[azloginCommand] = successExec;
5861
exec[azaccountSet] = successExec;
@@ -70,6 +73,7 @@ let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
7073
"CSM.json": [CSMJson],
7174
"CSMwithBicep.bicep": [CSMBicep],
7275
"CSMwithBicep.bicepparam": [CSMBicepParam],
76+
"CSMwithBicep.prod.bicepparam": [CSMBicepParamWithEnv],
7377
"CSMwithBicepWithWarning.bicep": [CSMBicepWithWarning],
7478
"CSMwithBicepWithError.bicep": [CSMBicepWithError],
7579
"CSMwithComments.json": [CSMwithComments],

_generated/AzureResourceManagerTemplateDeploymentV3_Node20/operations/Utils.ts

+13-5
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,14 @@ class Utils {
438438
filePath = filePath.replace('.bicep', '.json')
439439
}
440440
else{
441-
filePath = filePath.replace('.bicepparam', '.parameters.json')
441+
var fullFileName: string = filePath.split(path.sep).pop()
442+
var bicepParamExtension: string = '.bicepparam'
443+
if(fullFileName.split('.').length > 2){
444+
var nameArray: Array<string> = fullFileName.split('.')
445+
nameArray.splice(0, 1)
446+
bicepParamExtension = '.'+nameArray.join('.')
447+
}
448+
filePath = filePath.replace(bicepParamExtension, '.parameters.json')
442449
}
443450
await this.logoutAzure();
444451
}else{
@@ -474,18 +481,19 @@ class Utils {
474481
}
475482

476483
private static async execBicepBuild(filePath): Promise<void> {
484+
var fullFileName: string = filePath.split(path.sep).pop()
485+
var fileDir: string = filePath.replace(path.sep + fullFileName, '')
477486
var filePathExtension: string = filePath.split('.').pop();
487+
var fileName: string = filePath.split(path.sep).pop().split('.')[0];
478488
var finalPathExtension: string = ".json"
479-
489+
480490
if(filePathExtension === 'bicep'){
481491
const result: IExecSyncResult = tl.execSync("az", `bicep build --file ${filePath}`);
482492
if(result && result.code !== 0){
483493
throw new Error(tl.loc("BicepBuildFailed", result.stderr));
484494
}
485495
}
486496
else{
487-
var fileName: string = filePath.split(path.sep).pop().split('.')[0];
488-
var fileDir: string = filePath.replace(path.sep + fileName +'.bicepparam', '')
489497
finalPathExtension = ".parameters.json"
490498

491499
//Using --outfile to avoid overwriting primary bicep file in the case bicep and param file have the the same file name.
@@ -495,7 +503,7 @@ class Utils {
495503
}
496504
}
497505

498-
this.cleanupFileList.push(filePath.replace('.' + filePathExtension, finalPathExtension))
506+
this.cleanupFileList.push(fileDir + path.sep + fileName + finalPathExtension)
499507
}
500508

501509
private static async logoutAzure() {

0 commit comments

Comments
 (0)