Skip to content

Commit

Permalink
Fix Virtual Application post deployment script (#6350)
Browse files Browse the repository at this point in the history
* fix post deployment script

* change path
  • Loading branch information
vincent1173 authored Feb 2, 2018
1 parent f89fa98 commit 61d7ffa
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
5 changes: 3 additions & 2 deletions Tasks/AzureRmWebAppDeployment/azurermwebappdeployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async function main() {
tl.setResourcePath(path.join( __dirname, 'task.json'));
var taskParams: TaskParameters = TaskParametersUtility.getParameters();
var azureEndpoint: AzureEndpoint = await new AzureRMEndpoint(taskParams.connectedServiceName).getEndpoint();

var virtualApplicationPath: string;
console.log(tl.loc('GotconnectiondetailsforazureRMWebApp0', taskParams.WebAppName));
if(!taskParams.DeployToSlotFlag) {
taskParams.ResourceGroupName = await AzureResourceFilterUtility.getResourceGroupName(azureEndpoint, taskParams.WebAppName);
Expand Down Expand Up @@ -71,6 +71,7 @@ async function main() {
if(taskParams.VirtualApplication) {
physicalPath = await appServiceUtility.getPhysicalPath(taskParams.VirtualApplication);
await kuduServiceUtility.createPathIfRequired(physicalPath);
virtualApplicationPath = physicalPath;
}

webPackage = await FileTransformsUtility.applyTransformations(webPackage, taskParams);
Expand Down Expand Up @@ -112,7 +113,7 @@ async function main() {
}

if(taskParams.ScriptType) {
await kuduServiceUtility.runPostDeploymentScript(taskParams);
await kuduServiceUtility.runPostDeploymentScript(taskParams, virtualApplicationPath);
}

await appServiceUtility.updateScmTypeAndConfigurationDetails();
Expand Down
20 changes: 11 additions & 9 deletions Tasks/AzureRmWebAppDeployment/operations/KuduServiceUtility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,38 +34,40 @@ export class KuduServiceUtility {
}
}

public async runPostDeploymentScript(taskParams: TaskParameters): Promise<void> {
public async runPostDeploymentScript(taskParams: TaskParameters, directoryPath?: string): Promise<void> {
try {
directoryPath = (!!directoryPath) ? directoryPath : physicalRootPath.substring(1);

if(taskParams.TakeAppOfflineFlag) {
await this._appOfflineKuduService(physicalRootPath, true);
await this._appOfflineKuduService(directoryPath, true);
}

var scriptFile = this._getPostDeploymentScript(taskParams.ScriptType, taskParams.InlineScript, taskParams.ScriptPath, taskParams.isLinuxApp);
var uniqueID = this.getDeploymentID();
var fileExtension : string = taskParams.isLinuxApp ? '.sh' : '.cmd';
var mainCmdFilePath = path.join(__dirname, '..', 'postDeploymentScript', 'mainCmdFile' + fileExtension);
await this._appServiceKuduService.uploadFile(physicalRootPath, 'mainCmdFile_' + uniqueID + fileExtension, mainCmdFilePath);
await this._appServiceKuduService.uploadFile(physicalRootPath, 'kuduPostDeploymentScript_' + uniqueID + fileExtension, scriptFile.filePath);
await this._appServiceKuduService.uploadFile(directoryPath, 'mainCmdFile_' + uniqueID + fileExtension, mainCmdFilePath);
await this._appServiceKuduService.uploadFile(directoryPath, 'kuduPostDeploymentScript_' + uniqueID + fileExtension, scriptFile.filePath);
console.log(tl.loc('ExecuteScriptOnKudu'));
await this.runCommand('site\\wwwroot',
await this.runCommand(directoryPath,
'mainCmdFile_' + uniqueID + fileExtension + ' ' + uniqueID,
30, 'script_result_' + uniqueID + '.txt');
await this._printPostDeploymentLogs(physicalRootPath, uniqueID);
await this._printPostDeploymentLogs(directoryPath, uniqueID);

}
catch(error) {
throw Error(tl.loc('FailedToRunScriptOnKuduError', error));
}
finally {
try {
await this._appServiceKuduService.uploadFile(physicalRootPath, 'delete_log_file_' + uniqueID + fileExtension, path.join(__dirname, '..', 'postDeploymentScript', 'deleteLogFile' + fileExtension));
await this.runCommand('site\\wwwroot', 'delete_log_file_' + uniqueID + fileExtension + ' ' + uniqueID, 0, null);
await this._appServiceKuduService.uploadFile(directoryPath, 'delete_log_file_' + uniqueID + fileExtension, path.join(__dirname, '..', 'postDeploymentScript', 'deleteLogFile' + fileExtension));
await this.runCommand(directoryPath, 'delete_log_file_' + uniqueID + fileExtension + ' ' + uniqueID, 0, null);
}
catch(error) {
tl.debug('Unable to delete log files : ' + error);
}
if(taskParams.TakeAppOfflineFlag) {
await this._appOfflineKuduService(physicalRootPath, false);
await this._appOfflineKuduService(directoryPath, false);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureRmWebAppDeployment/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"version": {
"Major": 3,
"Minor": 3,
"Patch": 38
"Patch": 39
},
"releaseNotes": "What's new in Version 3.0: <br/>&nbsp;&nbsp;Supports File Transformations (XDT) <br/>&nbsp;&nbsp;Supports Variable Substitutions(XML, JSON) <br/>Click [here](https://aka.ms/azurermwebdeployreadme) for more Information.",
"minimumAgentVersion": "2.104.1",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureRmWebAppDeployment/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"version": {
"Major": 3,
"Minor": 3,
"Patch": 38
"Patch": 39
},
"releaseNotes": "ms-resource:loc.releaseNotes",
"minimumAgentVersion": "2.104.1",
Expand Down

0 comments on commit 61d7ffa

Please sign in to comment.