Skip to content

Commit 4596931

Browse files
authored
Azure App Service Deploy Task - BugBash Fix (#3305)
1 parent 7f2d005 commit 4596931

File tree

13 files changed

+197
-22
lines changed

13 files changed

+197
-22
lines changed

Tasks/AzureRmWebAppDeployment/Strings/resources.resjson/en-US/resources.resjson

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"loc.input.help.JSONFiles": "Provide new line separated list of JSON files to substitute the variable values. Files names are to be provided relative to the root folder. <br/> To substitute JSON variables that are nested or hierarchical, specify them using JSONPath expressions. <br/> <br/> For example, to replace the value of ‘ConnectionString’ in the sample below, you need to define a variable as ‘Data.DefaultConnection.ConnectionString’ in the build/release definition (or release definition’s environment). <br/> {<br/>&nbsp;&nbsp;\"Data\": {<br/>&nbsp;&nbsp;&nbsp;&nbsp;\"DefaultConnection\": {<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"ConnectionString\": \"Server=(localdb)\\SQLEXPRESS;Database=MyDB;Trusted_Connection=True\"<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;}<br/> }<br/> Variable Substitution is run after configuration transforms. <br/><br/> Note: Build/Release’s system definition variables are excluded in substitution",
4545
"loc.messages.Invalidwebapppackageorfolderpathprovided": "Invalid App Service package or folder path provided: %s",
4646
"loc.messages.SetParamFilenotfound0": "Set parameters file not found: %s",
47-
"loc.messages.XDTTransformationsappliedsuccessfully": "XDT Transformations applied successfully",
47+
"loc.messages.XDTTransformationsappliedsuccessfully": "XML Transformations applied successfully",
4848
"loc.messages.GotconnectiondetailsforazureRMWebApp0": "Got connection details for Azure App Service:'%s'",
4949
"loc.messages.ErrorNoSuchDeployingMethodExists": "Error : No such deploying method exists",
5050
"loc.messages.UnabletoretrieveconnectiondetailsforazureRMWebApp": "Unable to retrieve connection details for Azure App Service : %s. Status Code: %s (%s)",
@@ -68,7 +68,7 @@
6868
"loc.messages.UnsupportedinstalledversionfoundforMSDeployversionshouldbealteast3orabove": "Unsupported installed version: %s found for MSDeploy. version should be alteast 3 or above",
6969
"loc.messages.UnabletofindthelocationofMSDeployfromregistryonmachineError": "Unable to find the location of MS Deploy from registry on machine (Error : %s)",
7070
"loc.messages.Nopackagefoundwithspecifiedpattern": "No package found with specified pattern",
71-
"loc.messages.MorethanonepackagematchedwithspecifiedpatternPleaserestrainthesearchpatern": "More than one package matched with specified pattern. Please restrain the search pattern.",
71+
"loc.messages.MorethanonepackagematchedwithspecifiedpatternPleaserestrainthesearchpattern": "More than one package matched with specified pattern. Please restrain the search pattern.",
7272
"loc.messages.Trytodeploywebappagainwithappofflineoptionselected": "Try to deploy app service again with Take application offline option selected.",
7373
"loc.messages.Trytodeploywebappagainwithrenamefileoptionselected": "Try to deploy app service again with Rename locked files option selected.",
7474
"loc.messages.NOJSONfilematchedwithspecificpattern": "NO JSON file matched with specific pattern",
@@ -93,5 +93,8 @@
9393
"loc.messages.KuduPhysicalpathCreatedSuccessfully": "Kudu physical path created successfully : %s",
9494
"loc.messages.FailedtocreateKuduPhysicalPath": "Failed to create kudu physical path. %s: %s",
9595
"loc.messages.FailedtocheckphysicalPath": "Failed to check kudu physical path. %s: %s",
96-
"loc.messages.VirtualApplicationDoesNotExist": "Virtual application doesn't exists : %s"
96+
"loc.messages.VirtualApplicationDoesNotExist": "Virtual application doesn't exists : %s",
97+
"loc.messages.JSONParseError": "Unable to parse JSON file: %s. Error: %s",
98+
"loc.messages.JSONvariablesubstitutionappliedsuccessfully": "JSON variable substitution applied successfully.",
99+
"loc.messages.XMLvaiablesubstitutionappliedsuccessfully": "XML vaiable substitution applied successfully."
97100
}

Tasks/AzureRmWebAppDeployment/Tests/L0.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ describe('AzureRmWebAppDeployment Suite', function() {
219219

220220
assert(tr.invokedToolCount == 0, 'should not have invoked any tool');
221221
assert(tr.stderr.length > 0 || tr.errorIssues.length > 0, 'should have written to stderr');
222-
var expectedErr = 'Error: loc_mock_MorethanonepackagematchedwithspecifiedpatternPleaserestrainthesearchpatern';
222+
var expectedErr = 'Error: loc_mock_MorethanonepackagematchedwithspecifiedpatternPleaserestrainthesearchpattern';
223223
assert(tr.stdErrContained(expectedErr) || tr.createdErrorIssue(expectedErr), 'should have said: ' + expectedErr);
224224
var expectedOut = 'Failed to update history to kudu';
225225
assert(tr.stdout.search(expectedOut) >= 0, 'should have said: ' + expectedOut);
@@ -352,7 +352,7 @@ describe('AzureRmWebAppDeployment Suite', function() {
352352
let tp = path.join(__dirname, 'L0WindowsXdtTransformation.js');
353353
let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp);
354354
tr.run();
355-
355+
356356
var expectedOut = 'Updated history to kudu';
357357
assert(tr.invokedToolCount == 3, 'should have invoked tool thrice');
358358
assert(tr.stderr.length == 0 && tr.errorIssues.length == 0, 'should not have written to stderr');
@@ -367,7 +367,7 @@ describe('AzureRmWebAppDeployment Suite', function() {
367367
let tp = path.join(__dirname, 'L0WindowsXdtTransformationFail.js');
368368
let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp);
369369
tr.run();
370-
370+
371371
var expectedErr = "Error: loc_mock_XdtTransformationErrorWhileTransforming";
372372
assert(tr.invokedToolCount == 1, 'should have invoked tool only once');
373373
assert(tr.stderr.length > 0 || tr.errorIssues.length > 0, 'should have written to stderr');

Tasks/AzureRmWebAppDeployment/Tests/L0JsonVarSub.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
5050
"rmRF": {
5151
"DefaultWorkingDirectory\\msDeployCommand.bat": {
5252
"success": true
53+
},
54+
"temp_web_package_random_path": {
55+
"success": true
5356
}
5457
},
5558
"exec": {
@@ -240,5 +243,23 @@ tr.registerMock('webdeployment-common/jsonvariablesubstitutionutility.js', {
240243
}
241244
});
242245

246+
tr.registerMock('webdeployment-common/utility.js', {
247+
isInputPkgIsFolder: function() {
248+
return false;
249+
},
250+
fileExists: function() {
251+
return true;
252+
},
253+
canUseWebDeploy: function() {
254+
return true;
255+
},
256+
findfiles: function() {
257+
return ['webDeployPkg']
258+
},
259+
generateTemporaryFolderOrZipPath: function() {
260+
return 'temp_web_package_random_path';
261+
}
262+
});
263+
243264
tr.setAnswers(a);
244265
tr.run();

Tasks/AzureRmWebAppDeployment/Tests/L0NonWindowsFailArchive.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
8585
"build.sourceVersionAuthor": "author",
8686
"release.releaseUri": "vstfs:///ReleaseManagement/Release/1",
8787
"agent.name": "agent"
88+
},
89+
"rmRF": {
90+
"temp_web_package_random_path": {
91+
"success": true
92+
}
8893
}
8994
}
9095

@@ -204,5 +209,24 @@ tr.registerMock('webdeployment-common/ziputility.js', {
204209
getArchivedEntries: zipUtility.getArchivedEntries
205210
});
206211

212+
213+
tr.registerMock('webdeployment-common/utility.js', {
214+
isInputPkgIsFolder: function() {
215+
return true;
216+
},
217+
fileExists: function() {
218+
return true;
219+
},
220+
canUseWebDeploy: function() {
221+
return false;
222+
},
223+
findfiles: function() {
224+
return ['webDeployPkg']
225+
},
226+
generateTemporaryFolderOrZipPath: function() {
227+
return 'temp_web_package_random_path';
228+
}
229+
});
230+
207231
tr.setAnswers(a);
208232
tr.run();

Tasks/AzureRmWebAppDeployment/Tests/L0NonWindowsFolderPkg.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
8585
"build.sourceVersionAuthor": "author",
8686
"release.releaseUri": "vstfs:///ReleaseManagement/Release/1",
8787
"agent.name": "agent"
88+
},
89+
"rmRF": {
90+
"temp_web_package_random_path": {
91+
"success": true
92+
}
8893
}
8994
}
9095

@@ -204,5 +209,23 @@ tr.registerMock('webdeployment-common/ziputility.js', {
204209
}
205210
});
206211

212+
tr.registerMock('webdeployment-common/utility.js', {
213+
isInputPkgIsFolder: function() {
214+
return true;
215+
},
216+
fileExists: function() {
217+
return true;
218+
},
219+
canUseWebDeploy: function() {
220+
return false;
221+
},
222+
findfiles: function() {
223+
return ['webDeployPkg']
224+
},
225+
generateTemporaryFolderOrZipPath: function() {
226+
return 'temp_web_package_random_path';
227+
}
228+
});
229+
207230
tr.setAnswers(a);
208231
tr.run();

Tasks/AzureRmWebAppDeployment/Tests/L0WindowsXdtTransformation.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
6464
"rmRF": {
6565
"DefaultWorkingDirectory\\msDeployCommand.bat": {
6666
"success": true
67+
},
68+
"temp_web_package_random_path": {
69+
"success": true
70+
},
71+
"DefaultWorkingDirectory\temp_web_package.zip": {
72+
"success": true
6773
}
6874
},
6975
"exist": {
@@ -75,8 +81,8 @@ let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
7581
"Invalid_webAppPkg" : [],
7682
"webAppPkg.zip": ["webAppPkg.zip"],
7783
"webAppPkg": ["webAppPkg"],
78-
"DefaultWorkingDirectory\\temp_web_package_folder\\**\\*.config": ["path1/web.config", "path1/web.Release.config", "path1/web.Debug.config", "path2/web.config", "path2/web.Debug.config"],
79-
"DefaultWorkingDirectory/temp_web_package_folder/**/*.config": ["web.config", "web.Release.config", "web.Debug.config"]
84+
"temp_web_package_random_path\\**\\*.config": ["path1/web.config", "path1/web.Release.config", "path1/web.Debug.config", "path2/web.config", "path2/web.Debug.config"],
85+
"temp_web_package_random_path\**\*.config": ["web.config", "web.Release.config", "web.Debug.config"]
8086
},
8187
"getVariable": {
8288
"ENDPOINT_AUTH_AzureRMSpn": "{\"parameters\":{\"serviceprincipalid\":\"spId\",\"serviceprincipalkey\":\"spKey\",\"tenantid\":\"tenant\"},\"scheme\":\"ServicePrincipal\"}",
@@ -191,5 +197,23 @@ tr.registerMock('webdeployment-common/ziputility.js', {
191197
}
192198
});
193199

200+
tr.registerMock('webdeployment-common/utility.js', {
201+
isInputPkgIsFolder: function() {
202+
return false;
203+
},
204+
fileExists: function() {
205+
return true;
206+
},
207+
canUseWebDeploy: function() {
208+
return true;
209+
},
210+
findfiles: function() {
211+
return ['webDeployPkg']
212+
},
213+
generateTemporaryFolderOrZipPath: function() {
214+
return 'temp_web_package_random_path';
215+
}
216+
});
217+
194218
tr.setAnswers(a);
195219
tr.run();

Tasks/AzureRmWebAppDeployment/Tests/L0WindowsXdtTransformationFail.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
7070
"Invalid_webAppPkg" : [],
7171
"webAppPkg.zip": ["webAppPkg.zip"],
7272
"webAppPkg": ["webAppPkg"],
73-
"DefaultWorkingDirectory\\temp_web_package_folder\\**\\*.config": ["path1/web.config", "path1/web.Release.config", "path1/web.Debug.config", "path2/web.config", "path2/web.Debug.config"],
74-
"DefaultWorkingDirectory/temp_web_package_folder/**/*.config": ["web.config", "web.Release.config", "web.Debug.config"]
73+
"temp_web_package_random_path\\**\\*.config": ["path1/web.config", "path1/web.Release.config", "path1/web.Debug.config", "path2/web.config", "path2/web.Debug.config"],
74+
"temp_web_package_random_path/**/*.config": ["web.config", "web.Release.config", "web.Debug.config"]
7575
},
7676
"getVariable": {
7777
"ENDPOINT_AUTH_AzureRMSpn": "{\"parameters\":{\"serviceprincipalid\":\"spId\",\"serviceprincipalkey\":\"spKey\",\"tenantid\":\"tenant\"},\"scheme\":\"ServicePrincipal\"}",
@@ -186,5 +186,23 @@ tr.registerMock('webdeployment-common/ziputility.js', {
186186
}
187187
});
188188

189+
tr.registerMock('webdeployment-common/utility.js', {
190+
isInputPkgIsFolder: function() {
191+
return false;
192+
},
193+
fileExists: function() {
194+
return true;
195+
},
196+
canUseWebDeploy: function() {
197+
return true;
198+
},
199+
findfiles: function() {
200+
return ['webDeployPkg']
201+
},
202+
generateTemporaryFolderOrZipPath: function() {
203+
return 'temp_web_package_random_path';
204+
}
205+
});
206+
189207
tr.setAnswers(a);
190208
tr.run();

Tasks/AzureRmWebAppDeployment/Tests/L0XmlVarSub.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
5757
"rmRF": {
5858
"DefaultWorkingDirectory\\msDeployCommand.bat": {
5959
"success": true
60+
},
61+
"temp_web_package_random_path": {
62+
"success": true
6063
}
6164
},
6265
"exec": {
@@ -218,5 +221,23 @@ tr.registerMock('webdeployment-common/xmlvariablesubstitutionutility.js', {
218221
}
219222
});
220223

224+
tr.registerMock('webdeployment-common/utility.js', {
225+
isInputPkgIsFolder: function() {
226+
return false;
227+
},
228+
fileExists: function() {
229+
return true;
230+
},
231+
canUseWebDeploy: function() {
232+
return true;
233+
},
234+
findfiles: function() {
235+
return ['webDeployPkg']
236+
},
237+
generateTemporaryFolderOrZipPath: function() {
238+
return 'temp_web_package_random_path';
239+
}
240+
});
241+
221242
tr.setAnswers(a);
222243
tr.run();

Tasks/AzureRmWebAppDeployment/azurermwebappdeployment.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ async function run() {
3737
var endPointAuthCreds = tl.getEndpointAuthorization(connectedServiceName, true);
3838

3939
var isDeploymentSuccess: boolean = true;
40+
var tempPackagePath = null;
4041

4142
var endPoint = new Array();
4243
endPoint["servicePrincipalClientID"] = tl.getEndpointAuthorizationParameter(connectedServiceName, 'serviceprincipalid', true);
@@ -63,15 +64,15 @@ async function run() {
6364
}
6465

6566
if(availableWebPackages.length > 1) {
66-
throw new Error(tl.loc('MorethanonepackagematchedwithspecifiedpatternPleaserestrainthesearchpatern'));
67+
throw new Error(tl.loc('MorethanonepackagematchedwithspecifiedpatternPleaserestrainthesearchpattern'));
6768
}
6869
webDeployPkg = availableWebPackages[0];
6970

7071
var isFolderBasedDeployment = utility.isInputPkgIsFolder(webDeployPkg);
7172

7273
if(JSONFiles.length != 0 || xmlTransformation || xmlVariableSubstitution) {
7374

74-
var folderPath = path.join(tl.getVariable('System.DefaultWorkingDirectory'), 'temp_web_package_folder');
75+
var folderPath = utility.generateTemporaryFolderOrZipPath(tl.getVariable('System.DefaultWorkingDirectory'), true);
7576
if(isFolderBasedDeployment) {
7677
tl.cp(path.join(webDeployPkg, '/*'), folderPath, '-rf', false);
7778
}
@@ -95,13 +96,23 @@ async function run() {
9596

9697
if(xmlVariableSubstitution) {
9798
await xmlSubstitutionUtility.substituteAppSettingsVariables(folderPath);
99+
tl._writeLine(tl.loc('XMLvaiablesubstitutionappliedsuccessfully'));
98100
}
99101

100102
if(JSONFiles.length != 0) {
101103
jsonSubstitutionUtility.jsonVariableSubstitution(folderPath, JSONFiles);
104+
tl._writeLine(tl.loc('JSONvariablesubstitutionappliedsuccessfully'));
105+
}
106+
if(isFolderBasedDeployment) {
107+
tempPackagePath = folderPath;
108+
webDeployPkg = folderPath;
109+
}
110+
else {
111+
var tempWebPackageZip = utility.generateTemporaryFolderOrZipPath(tl.getVariable('System.DefaultWorkingDirectory'), false);
112+
webDeployPkg = await zipUtility.archiveFolder(folderPath, "", tempWebPackageZip);
113+
tempPackagePath = webDeployPkg;
114+
tl.rmRF(folderPath, true);
102115
}
103-
104-
webDeployPkg = (isFolderBasedDeployment) ? folderPath : await zipUtility.archiveFolder(folderPath, tl.getVariable('System.DefaultWorkingDirectory'), 'temp_web_package.zip')
105116
}
106117

107118
if(virtualApplication) {
@@ -174,6 +185,9 @@ async function run() {
174185
tl.warning(error);
175186
}
176187
}
188+
if(tempPackagePath) {
189+
tl.rmRF(tempPackagePath);
190+
}
177191
}
178192

179193

@@ -188,12 +202,13 @@ async function run() {
188202
*
189203
*/
190204
async function DeployUsingKuduDeploy(webDeployPkg, azureWebAppDetails, publishingProfile, virtualApplication, isFolderBasedDeployment, takeAppOfflineFlag) {
191-
205+
var tempPackagePath = null;
192206
try {
193207
var virtualApplicationMappings = azureWebAppDetails.properties.virtualApplications;
194208
var webAppZipFile = webDeployPkg;
195209
if(isFolderBasedDeployment) {
196-
webAppZipFile = await zipUtility.archiveFolder(webDeployPkg, tl.getVariable('System.DefaultWorkingDirectory'), 'temp_web_app_package.zip');
210+
tempPackagePath = utility.generateTemporaryFolderOrZipPath(tl.getVariable('System.DefaultWorkingDirectory'), false);
211+
webAppZipFile = await zipUtility.archiveFolder(webDeployPkg, "", tempPackagePath);
197212
tl.debug("Compressed folder " + webDeployPkg + " into zip : " + webAppZipFile);
198213
} else {
199214
if (await kuduUtility.containsParamFile(webAppZipFile)) {
@@ -218,6 +233,11 @@ async function DeployUsingKuduDeploy(webDeployPkg, azureWebAppDetails, publishin
218233
tl.error(tl.loc('Failedtodeploywebsite'));
219234
throw Error(error);
220235
}
236+
finally {
237+
if(tempPackagePath) {
238+
tl.rmRF(tempPackagePath, true);
239+
}
240+
}
221241
}
222242

223243
async function updateScmType(SPN, webAppName: string, resourceGroupName: string, deployToSlotFlag: boolean, slotName: string) {

0 commit comments

Comments
 (0)