Skip to content

Commit 76f54a3

Browse files
committed
Merge branch 'releases/m114' of https://github.com/Microsoft/vsts-tasks into releases/m114
2 parents 1cfcf9d + be5d2dc commit 76f54a3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2157
-144
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,5 +158,7 @@
158158
"loc.messages.DeletingMGAgentOnVMs": "Deleting machine group agent on virtual machines",
159159
"loc.messages.AddingExtensionFailed": "Addition of extension on vm %s failed",
160160
"loc.messages.TimeoutWhileWaiting": "Timed out while waiting",
161-
"loc.messages.InvalidTemplateLocation": "The template location supplied is invalid. Task only supports 'Linked artifact' or 'URL of the file'"
161+
"loc.messages.InvalidTemplateLocation": "The template location supplied is invalid. Task only supports 'Linked artifact' or 'URL of the file'",
162+
"loc.messages.EncodingNotSupported": "Encoding of the file '%s' is '%s' which is not supported. Supported encodings are ['utf-8', 'utf-16le']",
163+
"loc.messages.CouldNotDetectEncoding": "Could not detect encoding of file '%s'"
162164
}

Tasks/AzureResourceGroupDeployment/models/DeployAzureRG.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export class AzureRGTaskParameters {
6666
var tenantId: string = endpointAuth.parameters["tenantid"];
6767
var armUrl: string = tl.getEndpointUrl(connectedService, true);
6868
var envAuthorityUrl: string = tl.getEndpointDataParameter(connectedService, 'environmentAuthorityUrl', true);
69+
envAuthorityUrl = (envAuthorityUrl != null) ? envAuthorityUrl : "https://login.windows.net/";
6970
var credentials = new msRestAzure.ApplicationTokenCredentials(servicePrincipalId, tenantId, servicePrincipalKey, armUrl, envAuthorityUrl);
7071
return credentials;
7172
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
//File Encoding detected to be : utf-32be, which is not supported by Node.js
2+
//'Unable to detect encoding of file ' + typeCode
3+
//'File buffer is too short to detect encoding type'
4+
var fs = require('fs');
5+
import tl = require('vsts-task-lib');
6+
7+
export class FileEncoding {
8+
public type: string;
9+
public usesBOM: boolean;
10+
constructor(type: string, usesBOM: boolean) {
11+
this.type = type;
12+
this.usesBOM = usesBOM;
13+
}
14+
}
15+
16+
function detectFileEncodingWithBOM(fileName: string, buffer: Buffer) {
17+
tl.debug('Detecting file encoding using BOM');
18+
var type: string;
19+
if (buffer.slice(0, 3).equals(new Buffer([239, 187, 191]))) {
20+
type = 'utf-8';
21+
}
22+
else if (buffer.slice(0, 4).equals(new Buffer([255, 254, 0, 0]))) {
23+
type = 'utf-32le';
24+
}
25+
else if (buffer.slice(0, 2).equals(new Buffer([254, 255]))) {
26+
type = 'utf-16be';
27+
}
28+
else if (buffer.slice(0, 2).equals(new Buffer([255, 254]))) {
29+
type = 'utf-16le';
30+
}
31+
else if (buffer.slice(0, 4).equals(new Buffer([0, 0, 254, 255]))) {
32+
type = 'utf-32be';
33+
}
34+
else {
35+
tl.debug('Unable to detect File encoding using BOM');
36+
return null;
37+
}
38+
return new FileEncoding(type, true);
39+
}
40+
41+
function detectFileEncodingWithoutBOM(fileName: string, buffer: Buffer) {
42+
tl.debug('Detecting file encoding without BOM');
43+
if (buffer.length < 4) {
44+
tl.debug('Short file buffer error on file ' + fileName + '. length: ' + buffer.length);
45+
}
46+
47+
var typeCode = 0;
48+
var type: string;
49+
var codeForUtf8 = 0
50+
for (var index = 0; index < 4 && index < buffer.length; index++) {
51+
typeCode = typeCode << 1;
52+
typeCode = typeCode | (buffer[index] > 0 ? 1 : 0);
53+
codeForUtf8 = codeForUtf8 << 1;
54+
codeForUtf8++;
55+
}
56+
switch (typeCode) {
57+
case 1:
58+
type = 'utf-32be';
59+
break;
60+
case 5:
61+
type = 'utf-16be';
62+
break;
63+
case 8:
64+
type = 'utf-32le';
65+
break;
66+
case 10:
67+
type = 'utf-16le';
68+
break;
69+
default:
70+
if (codeForUtf8 == typeCode) {
71+
type = 'utf-8';
72+
}
73+
else {
74+
return null;
75+
}
76+
}
77+
return new FileEncoding(type, false);
78+
}
79+
export function detectFileEncoding(fileName: string, buffer: Buffer): FileEncoding {
80+
81+
var fileEncoding: FileEncoding = detectFileEncodingWithBOM(fileName, buffer);
82+
if (fileEncoding == null) {
83+
fileEncoding = detectFileEncodingWithoutBOM(fileName, buffer);
84+
}
85+
86+
if (fileEncoding == null) {
87+
throw new Error(tl.loc("CouldNotDetectEncoding", fileName));
88+
}
89+
return fileEncoding;
90+
}
91+
92+
export function readFileContentsAsText(fileName: string): string {
93+
var buffer = fs.readFileSync(fileName);
94+
var supportedFileEncodings = ["utf-8", "utf-16le"]
95+
var fileEncoding = detectFileEncoding(fileName, buffer);
96+
if (supportedFileEncodings.indexOf(fileEncoding.type) < 0) {
97+
throw new Error(tl.loc('EncodingNotSupported', fileName, fileEncoding.type));
98+
}
99+
var fileContents: string = buffer.toString(fileEncoding.type);
100+
if (fileEncoding.usesBOM) {
101+
fileContents = fileContents.slice(1);
102+
}
103+
return fileContents;
104+
}

Tasks/AzureResourceGroupDeployment/operations/ResourceGroup.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import winRM = require("./WinRMExtensionHelper");
1515
import mgExtensionHelper = require("./MachineGroupExtensionHelper");
1616
var parameterParser = require("./ParameterParser").parse;
1717
import utils = require("./Utils");
18+
import fileEncoding = require('./FileEncoding');
1819

1920
var httpClient = require('vso-node-api/HttpClient');
2021
var httpObj = new httpClient.HttpCallbackClient("VSTS_AGENT");
@@ -190,7 +191,7 @@ export class ResourceGroup {
190191
var template: Object;
191192
try {
192193
tl.debug("Loading CSM Template File.. " + this.taskParameters.csmFile);
193-
template = JSON.parse(fs.readFileSync(this.taskParameters.csmFile, 'UTF-8'));
194+
template = JSON.parse(fileEncoding.readFileContentsAsText(this.taskParameters.csmFile));
194195
tl.debug("Loaded CSM File");
195196
}
196197
catch (error) {
@@ -202,9 +203,9 @@ export class ResourceGroup {
202203
if (utils.isNonEmpty(this.taskParameters.csmParametersFile)) {
203204
if (!fs.lstatSync(this.taskParameters.csmParametersFile).isDirectory()) {
204205
tl.debug("Loading Parameters File.. " + this.taskParameters.csmParametersFile);
205-
var parameterFile = fs.readFileSync(this.taskParameters.csmParametersFile, 'UTF-8');
206+
var parameterFile = JSON.parse(fileEncoding.readFileContentsAsText(this.taskParameters.csmParametersFile));
206207
tl.debug("Loaded Parameters File");
207-
parameters = JSON.parse(parameterFile).parameters;
208+
parameters = parameterFile["parameters"];
208209
}
209210
}
210211
}

Tasks/AzureResourceGroupDeployment/task.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 2,
1616
"Minor": 0,
17-
"Patch": 2
17+
"Patch": 4
1818
},
1919
"demands": [],
2020
"minimumAgentVersion": "2.0.0",
@@ -367,6 +367,8 @@
367367
"DeletingMGAgentOnVMs": "Deleting machine group agent on virtual machines",
368368
"AddingExtensionFailed": "Addition of extension on vm %s failed",
369369
"TimeoutWhileWaiting": "Timed out while waiting",
370-
"InvalidTemplateLocation": "The template location supplied is invalid. Task only supports 'Linked artifact' or 'URL of the file'"
370+
"InvalidTemplateLocation": "The template location supplied is invalid. Task only supports 'Linked artifact' or 'URL of the file'",
371+
"EncodingNotSupported": "Encoding of the file '%s' is '%s' which is not supported. Supported encodings are ['utf-8', 'utf-16le']",
372+
"CouldNotDetectEncoding": "Could not detect encoding of file '%s'"
371373
}
372374
}

Tasks/AzureResourceGroupDeployment/task.loc.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 2,
1616
"Minor": 0,
17-
"Patch": 2
17+
"Patch": 4
1818
},
1919
"demands": [],
2020
"minimumAgentVersion": "2.0.0",
@@ -367,6 +367,8 @@
367367
"DeletingMGAgentOnVMs": "ms-resource:loc.messages.DeletingMGAgentOnVMs",
368368
"AddingExtensionFailed": "ms-resource:loc.messages.AddingExtensionFailed",
369369
"TimeoutWhileWaiting": "ms-resource:loc.messages.TimeoutWhileWaiting",
370-
"InvalidTemplateLocation": "ms-resource:loc.messages.InvalidTemplateLocation"
370+
"InvalidTemplateLocation": "ms-resource:loc.messages.InvalidTemplateLocation",
371+
"EncodingNotSupported": "ms-resource:loc.messages.EncodingNotSupported",
372+
"CouldNotDetectEncoding": "ms-resource:loc.messages.CouldNotDetectEncoding"
371373
}
372374
}

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
"loc.input.help.AdditionalArguments": "Additional Web Deploy arguments following the syntax -key:value .<br />These will be applied when deploying the Azure App Service. Example: -disableLink:AppPoolExtension -disableLink:ContentExtension.<br />For more examples of Web Deploy operation settings, refer to [this](https://go.microsoft.com/fwlink/?linkid=838471).",
3737
"loc.input.label.RenameFilesFlag": "Rename locked files",
3838
"loc.input.help.RenameFilesFlag": "Select the option to enable msdeploy flag MSDEPLOY_RENAME_FILES_FLAG in Azure App Service application settings. The option if set enables msdeploy to rename locked files that are locked during app deployment",
39+
"loc.input.label.ScriptType": "Deployment script type",
40+
"loc.input.help.ScriptType": "Customize the deployment by providing a script that will run on the Azure App service. For example restore packages for Node, PHP, Python applications. [Learn more](https://go.microsoft.com/fwlink/?linkid=843471).",
41+
"loc.input.label.InlineScript": "Inline Script",
42+
"loc.input.label.ScriptPath": "Deployment script path",
3943
"loc.input.label.XmlTransformation": "XML transformation",
4044
"loc.input.help.XmlTransformation": "The config transfoms will be run for `*.Release.config` and `*.<EnvironmentName>.config` on the `*.config file`.<br/> Config transforms will be run prior to the Variable Substitution.<br/>XML transformations are supported only for Windows platform.",
4145
"loc.input.label.XmlVariableSubstitution": "XML variable substitution",
@@ -57,8 +61,8 @@
5761
"loc.messages.Unabletoretrievewebappsettings": "Unable to retrieve App Service application settings. [Status Code: '%s', Error Message: '%s']",
5862
"loc.messages.Unabletoupdatewebappsettings": "Unable to update App service application settings. [Status Code: '%s', Error Message: '%s']",
5963
"loc.messages.CannotupdatedeploymentstatusuniquedeploymentIdCannotBeRetrieved": "Cannot update deployment status : Unique Deployment ID cannot be retrieved",
60-
"loc.messages.WebappsuccessfullypublishedatUrl0": "App Service successfully deployed at url %s",
61-
"loc.messages.Failedtodeploywebsite": "Failed to deploy website.",
64+
"loc.messages.PackageDeploymentSuccess": "Successfully deployed web package to App Service.",
65+
"loc.messages.PackageDeploymentFailed": "Failed to deploy web package to App Service.",
6266
"loc.messages.Runningcommand": "Running command: %s",
6367
"loc.messages.Deployingwebapplicationatvirtualpathandphysicalpath": "Deploying web package : %s at virtual path (physical path) : %s (%s)",
6468
"loc.messages.Successfullydeployedpackageusingkuduserviceat": "Successfully deployed package %s using kudu service at %s",
@@ -96,5 +100,19 @@
96100
"loc.messages.VirtualApplicationDoesNotExist": "Virtual application doesn't exists : %s",
97101
"loc.messages.JSONParseError": "Unable to parse JSON file: %s. Error: %s",
98102
"loc.messages.JSONvariablesubstitutionappliedsuccessfully": "JSON variable substitution applied successfully.",
99-
"loc.messages.XMLvariablesubstitutionappliedsuccessfully": "XML variable substitution applied successfully."
103+
"loc.messages.XMLvariablesubstitutionappliedsuccessfully": "XML variable substitution applied successfully.",
104+
"loc.messages.failedtoUploadFileToKudu": "Unable to upload file: %s to Kudu (%s). Status Code: %s (%s)",
105+
"loc.messages.failedtoUploadFileToKuduError": "Unable to upload file: %s to Kudu (%s). Error: %s",
106+
"loc.messages.ExecuteScriptOnKudu": "Executing given script on Kudu: %s",
107+
"loc.messages.FailedToRunScriptOnKuduError": "Unable to run the script on Kudu: %s. Error: %s",
108+
"loc.messages.FailedToRunScriptOnKudu": "Unable to run the script on Kudu: %s. Status Code: %s (%s)",
109+
"loc.messages.SciptExecutionOnKuduSuccess": "Successfully executed script on Kudu.",
110+
"loc.messages.SciptExecutionOnKuduFailed": "Executed script returned '%s' as return code. Error: %s",
111+
"loc.messages.FailedtoDeleteFileFromKudu": "Unable to delete file: %s from Kudu (%s). Status Code: %s (%s)",
112+
"loc.messages.FailedtoDeleteFileFromKuduError": "Unable to delete file: %s from Kudu (%s). Error: %s",
113+
"loc.messages.ScriptFileNotFound": "Script file '%s' not found.",
114+
"loc.messages.InvalidScriptFile": "Invalid script file '%s' provided. Valid extensions are .bat and .cmd",
115+
"loc.messages.RetryForTimeoutIssue": "Script execution failed with timeout issue. Retrying once again.",
116+
"loc.messages.stdoutFromScript": "Standard output from script: ",
117+
"loc.messages.stderrFromScript": "Standard error from script: "
100118
}

Tasks/AzureRmWebAppDeployment/Tests/L0.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,4 +467,16 @@ describe('AzureRmWebAppDeployment Suite', function() {
467467
assert(tr.stdout.search('## mkdir Successful ##') >= 0, 'should have created dir including dest folder');
468468
done();
469469
});
470+
471+
it('Validate webdepoyment-common.utility.runPostDeploymentScript()', (done:MochaDone) => {
472+
let tp = path.join(__dirname, "..", "node_modules", "webdeployment-common", "Tests", 'L0RunPostDeploymentScript.js');
473+
let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp);
474+
tr.run();
475+
476+
assert(tr.succeeded, 'task should have succeeded');
477+
assert(tr.stdout.search('PUT:https://mytestappKuduUrl/api/vfs//site/wwwroot/kuduPostDeploymentScript.cmd') >= 0, 'should have uploaded file');
478+
assert(tr.stdout.search('POST:https://mytestappKuduUrl/api/command') >= 0, 'should have executed script');
479+
assert(tr.stdout.search('DELETED:https://mytestappKuduUrl/api/vfs//site/wwwroot/kuduPostDeploymentScript.cmd') >= 0, 'should have removed file');
480+
done();
481+
});
470482
});

Tasks/AzureRmWebAppDeployment/azurermwebappdeployment.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ async function run() {
3232
var xmlTransformation: boolean = tl.getBoolInput('XmlTransformation', false);
3333
var JSONFiles = tl.getDelimitedInput('JSONFiles', '\n', false);
3434
var xmlVariableSubstitution: boolean = tl.getBoolInput('XmlVariableSubstitution', false);
35+
var scriptType: string = tl.getInput('ScriptType', false);
36+
var inlineScript: string = tl.getInput('InlineScript', false);
37+
var scriptPath: string = tl.getPathInput('ScriptPath', false);
3538
var endPointAuthCreds = tl.getEndpointAuthorization(connectedServiceName, true);
36-
3739
var isDeploymentSuccess: boolean = true;
3840
var tempPackagePath = null;
3941

@@ -126,6 +128,9 @@ async function run() {
126128
await DeployUsingKuduDeploy(webDeployPkg, azureWebAppDetails, publishingProfile, virtualApplication, isFolderBasedDeployment, takeAppOfflineFlag);
127129

128130
}
131+
if(scriptType) {
132+
await kuduUtility.runPostDeploymentScript(publishingProfile, scriptType, inlineScript, scriptPath, takeAppOfflineFlag);
133+
}
129134
await updateScmType(endPoint, webAppName, resourceGroupName, deployToSlotFlag, slotName);
130135

131136
} catch (error) {
@@ -187,10 +192,10 @@ async function DeployUsingKuduDeploy(webDeployPkg, azureWebAppDetails, publishin
187192
}
188193
}
189194
await kuduUtility.deployWebAppPackage(webAppZipFile, publishingProfile, virtualPath, physicalPath, takeAppOfflineFlag);
190-
console.log(tl.loc('WebappsuccessfullypublishedatUrl0', publishingProfile.destinationAppUrl));
195+
console.log(tl.loc('PackageDeploymentSuccess'));
191196
}
192197
catch(error) {
193-
tl.error(tl.loc('Failedtodeploywebsite'));
198+
tl.error(tl.loc('PackageDeploymentFailed'));
194199
throw Error(error);
195200
}
196201
finally {

0 commit comments

Comments
 (0)