azure-pipelines-tasks-webdeployment-common 4.230.0 → 4.230.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <configuration>
3
+ <startup useLegacyV2RuntimeActivationPolicy="true" >
4
+ <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
5
+ <supportedRuntime version="v2.0.50727" />
6
+ </startup>
7
+ </configuration>
@@ -8,6 +8,7 @@ declare var errorMessages: {
8
8
  };
9
9
  declare function checkParametersIfPresent(argumentString: string, argumentCheckArray: Array<string>): boolean;
10
10
  declare var defaultMSBuildPackageArgument: string;
11
+ declare var tokenAuthMSBuildPackageArgument: string;
11
12
  declare var packageWithSetParamArgument: string;
12
13
  declare var folderPackageArgument: string;
13
14
  declare var packageWithExcludeAppDataArgument: string;
@@ -26,6 +26,16 @@ if (checkParametersIfPresent(defaultMSBuildPackageArgument, ["-source:package=\"
26
26
  else {
27
27
  throw new Error('MSBUILD PACKAGE DEFAULT PARAMS FAILED');
28
28
  }
29
+ var tokenAuthMSBuildPackageArgument = msdeployUtility.getMSDeployCmdArgs('package.zip', 'webapp_name', {
30
+ publishUrl: 'publishUrl', userName: 'user', userPWD: 'token'
31
+ }, true, false, true, null, null, null, true, false, false, "Bearer");
32
+ console.log(` * MSBUILD TOKEN AUTH PARAMS: ${tokenAuthMSBuildPackageArgument}`);
33
+ if (checkParametersIfPresent(tokenAuthMSBuildPackageArgument, ["AuthType=\"'Bearer'\""])) {
34
+ console.log("MSBUILD TOKEN AUTH PARAMS PASSED");
35
+ }
36
+ else {
37
+ throw new Error('MSBUILD TOKEN AUTH PARAMS FAILED');
38
+ }
29
39
  var packageWithSetParamArgument = msdeployUtility.getMSDeployCmdArgs('package.zip', 'webapp_name', {
30
40
  publishUrl: 'http://webapp_name.scm.azurewebsites.net:443', userName: '$webapp_name', userPWD: 'webapp_password'
31
41
  }, false, false, true, null, 'temp_param.xml', null, false, false, true);
@@ -32,6 +32,18 @@ else {
32
32
  throw new Error('MSBUILD PACKAGE DEFAULT PARAMS FAILED');
33
33
  }
34
34
 
35
+ var tokenAuthMSBuildPackageArgument: string = msdeployUtility.getMSDeployCmdArgs('package.zip', 'webapp_name', {
36
+ publishUrl: 'publishUrl', userName: 'user', userPWD: 'token'
37
+ }, true, false, true, null, null, null, true, false, false, "Bearer");
38
+
39
+ console.log(` * MSBUILD TOKEN AUTH PARAMS: ${tokenAuthMSBuildPackageArgument}`);
40
+ if(checkParametersIfPresent(tokenAuthMSBuildPackageArgument, ["AuthType=\"'Bearer'\""])) {
41
+ console.log("MSBUILD TOKEN AUTH PARAMS PASSED");
42
+ }
43
+ else {
44
+ throw new Error('MSBUILD TOKEN AUTH PARAMS FAILED');
45
+ }
46
+
35
47
 
36
48
  var packageWithSetParamArgument: string = msdeployUtility.getMSDeployCmdArgs('package.zip', 'webapp_name', {
37
49
  publishUrl: 'http://webapp_name.scm.azurewebsites.net:443', userName: '$webapp_name', userPWD: 'webapp_password'
@@ -13,5 +13,5 @@ import { WebDeployArguments, WebDeployResult } from './msdeployutility';
13
13
  * @param additionalArguments Arguments provided by user
14
14
  *
15
15
  */
16
- export declare function DeployUsingMSDeploy(webDeployPkg: any, webAppName: any, publishingProfile: any, removeAdditionalFilesFlag: any, excludeFilesFromAppDataFlag: any, takeAppOfflineFlag: any, virtualApplication: any, setParametersFile: any, additionalArguments: any, isFolderBasedDeployment: any, useWebDeploy: any): Promise<void>;
17
- export declare function executeWebDeploy(WebDeployArguments: WebDeployArguments, publishingProfile: any): Promise<WebDeployResult>;
16
+ export declare function DeployUsingMSDeploy(webDeployPkg: any, webAppName: any, publishingProfile: any, removeAdditionalFilesFlag: any, excludeFilesFromAppDataFlag: any, takeAppOfflineFlag: any, virtualApplication: any, setParametersFile: any, additionalArguments: any, isFolderBasedDeployment: any, useWebDeploy: any, authType?: string): Promise<void>;
17
+ export declare function executeWebDeploy(webDeployArguments: WebDeployArguments): Promise<WebDeployResult>;
@@ -14,6 +14,7 @@ const tl = require("azure-pipelines-task-lib/task");
14
14
  const fs = require("fs");
15
15
  const path = require("path");
16
16
  const Q = require("q");
17
+ const msdeployutility_1 = require("./msdeployutility");
17
18
  var msDeployUtility = require('./msdeployutility.js');
18
19
  var utility = require('./utility.js');
19
20
  const DEFAULT_RETRY_COUNT = 3;
@@ -31,7 +32,7 @@ const DEFAULT_RETRY_COUNT = 3;
31
32
  * @param additionalArguments Arguments provided by user
32
33
  *
33
34
  */
34
- function DeployUsingMSDeploy(webDeployPkg, webAppName, publishingProfile, removeAdditionalFilesFlag, excludeFilesFromAppDataFlag, takeAppOfflineFlag, virtualApplication, setParametersFile, additionalArguments, isFolderBasedDeployment, useWebDeploy) {
35
+ function DeployUsingMSDeploy(webDeployPkg, webAppName, publishingProfile, removeAdditionalFilesFlag, excludeFilesFromAppDataFlag, takeAppOfflineFlag, virtualApplication, setParametersFile, additionalArguments, isFolderBasedDeployment, useWebDeploy, authType) {
35
36
  return __awaiter(this, void 0, void 0, function* () {
36
37
  var msDeployPath = yield msDeployUtility.getMSDeployFullPath();
37
38
  var msDeployDirectory = msDeployPath.slice(0, msDeployPath.lastIndexOf('\\') + 1);
@@ -43,7 +44,7 @@ function DeployUsingMSDeploy(webDeployPkg, webAppName, publishingProfile, remove
43
44
  setParametersFileName = setParametersFile.slice(setParametersFile.lastIndexOf('\\') + 1, setParametersFile.length);
44
45
  }
45
46
  var isParamFilePresentInPackage = isFolderBasedDeployment ? false : yield utility.isMSDeployPackage(webDeployPkg);
46
- var msDeployCmdArgs = msDeployUtility.getMSDeployCmdArgs(webDeployPkg, webAppName, publishingProfile, removeAdditionalFilesFlag, excludeFilesFromAppDataFlag, takeAppOfflineFlag, virtualApplication, setParametersFileName, additionalArguments, isParamFilePresentInPackage, isFolderBasedDeployment, useWebDeploy);
47
+ var msDeployCmdArgs = msDeployUtility.getMSDeployCmdArgs(webDeployPkg, webAppName, publishingProfile, removeAdditionalFilesFlag, excludeFilesFromAppDataFlag, takeAppOfflineFlag, virtualApplication, setParametersFileName, additionalArguments, isParamFilePresentInPackage, isFolderBasedDeployment, useWebDeploy, authType);
47
48
  var retryCountParam = tl.getVariable("appservice.msdeployretrycount");
48
49
  var retryCount = (retryCountParam && !(isNaN(Number(retryCountParam)))) ? Number(retryCountParam) : DEFAULT_RETRY_COUNT;
49
50
  try {
@@ -80,26 +81,31 @@ function DeployUsingMSDeploy(webDeployPkg, webAppName, publishingProfile, remove
80
81
  });
81
82
  }
82
83
  exports.DeployUsingMSDeploy = DeployUsingMSDeploy;
83
- function executeWebDeploy(WebDeployArguments, publishingProfile) {
84
+ function executeWebDeploy(webDeployArguments) {
84
85
  return __awaiter(this, void 0, void 0, function* () {
85
- var webDeployArguments = yield msDeployUtility.getWebDeployArgumentsString(WebDeployArguments, publishingProfile);
86
+ const args = yield msdeployutility_1.getWebDeployArgumentsString(webDeployArguments);
87
+ const originalPathVar = process.env.PATH;
86
88
  try {
87
- var msDeployPath = yield msDeployUtility.getMSDeployFullPath();
88
- var msDeployDirectory = msDeployPath.slice(0, msDeployPath.lastIndexOf('\\') + 1);
89
- var pathVar = process.env.PATH;
89
+ const msDeployPath = yield msdeployutility_1.getMSDeployFullPath();
90
+ const msDeployDirectory = msDeployPath.slice(0, msDeployPath.lastIndexOf('\\') + 1);
90
91
  process.env.PATH = msDeployDirectory + ";" + process.env.PATH;
91
- yield executeMSDeploy(webDeployArguments);
92
+ yield executeMSDeploy(args);
93
+ return {
94
+ isSuccess: true
95
+ };
92
96
  }
93
97
  catch (exception) {
94
- var msDeployErrorFilePath = tl.getVariable('System.DefaultWorkingDirectory') + '\\' + 'error.txt';
95
- var errorFileContent = tl.exist(msDeployErrorFilePath) ? fs.readFileSync(msDeployErrorFilePath, 'utf-8') : "";
98
+ const msDeployErrorFilePath = tl.getVariable('System.DefaultWorkingDirectory') + '\\' + 'error.txt';
99
+ const errorFileContent = tl.exist(msDeployErrorFilePath) ? fs.readFileSync(msDeployErrorFilePath, 'utf-8') : "";
96
100
  return {
97
101
  isSuccess: false,
98
102
  error: errorFileContent,
99
- errorCode: msDeployUtility.getWebDeployErrorCode(errorFileContent)
103
+ errorCode: msdeployutility_1.getWebDeployErrorCode(errorFileContent)
100
104
  };
101
105
  }
102
- return { isSuccess: true };
106
+ finally {
107
+ process.env.PATH = originalPathVar;
108
+ }
103
109
  });
104
110
  }
105
111
  exports.executeWebDeploy = executeWebDeploy;
package/module.json CHANGED
@@ -30,6 +30,10 @@
30
30
  "VariableSubstitutionInitiated" : "Initiated variable substitution in config file : %s",
31
31
  "ConfigFileUpdated" : "Config file : %s updated.",
32
32
  "SkippedUpdatingFile" : "Skipped Updating file: %s",
33
- "PwshNotAvailable": "##WARNING##:PowerShell Core (pwsh.exe) is not available on agent machine. Falling back to using Windows PowerShell (powershell.exe). This can cause reduced performance. Please install the newer version of PowerShell for improved performance."
33
+ "PwshNotAvailable": "##WARNING##:PowerShell Core (pwsh.exe) is not available on agent machine. Falling back to using Windows PowerShell (powershell.exe). This can cause reduced performance. Please install the newer version of PowerShell for improved performance.",
34
+ "UnabletofindthelocationofMSDeployfromregistryonmachineError": "Unable to find the location of MSDeploy from registry. Error: %s",
35
+ "MissingMSDeployVersionRegistryKey": "Missing MSDeploy Version registry key.",
36
+ "UnsupportedMSDeployVersion": "MSDeploy %s does not support token base authentication. Please upgrade to MSDeploy 9.0.7225.0 or higher.",
37
+ "MissingMSDeployInstallPathRegistryKey": "Missing MSDeploy InstallPath registry key."
34
38
  }
35
39
  }
@@ -4,7 +4,7 @@ import { Package } from './packageUtility';
4
4
  *
5
5
  * @param webAppPackage Web deploy package
6
6
  * @param webAppName web App Name
7
- * @param publishingProfile Azure RM Connection Details
7
+ * @param profile Azure RM Connection Details
8
8
  * @param removeAdditionalFilesFlag Flag to set DoNotDeleteRule rule
9
9
  * @param excludeFilesFromAppDataFlag Flag to prevent App Data from publishing
10
10
  * @param takeAppOfflineFlag Flag to enable AppOffline rule
@@ -13,17 +13,19 @@ import { Package } from './packageUtility';
13
13
  * @param additionalArguments Arguments provided by user
14
14
  * @param isParamFilePresentInPacakge Flag to check Paramter.xml file
15
15
  * @param isFolderBasedDeployment Flag to check if given web package path is a folder
16
+ * @param authType Type of authentication to use
16
17
  *
17
18
  * @returns string
18
19
  */
19
- export declare function getMSDeployCmdArgs(webAppPackage: string, webAppName: string, publishingProfile: any, removeAdditionalFilesFlag: boolean, excludeFilesFromAppDataFlag: boolean, takeAppOfflineFlag: boolean, virtualApplication: string, setParametersFile: string, additionalArguments: string, isParamFilePresentInPacakge: boolean, isFolderBasedDeployment: boolean, useWebDeploy: boolean): string;
20
- export declare function getWebDeployArgumentsString(webDeployArguments: WebDeployArguments, publishingProfile: any): Promise<string>;
20
+ export declare function getMSDeployCmdArgs(webAppPackage: string, webAppName: string, profile: any, removeAdditionalFilesFlag: boolean, excludeFilesFromAppDataFlag: boolean, takeAppOfflineFlag: boolean, virtualApplication: string, setParametersFile: string, additionalArguments: string, isParamFilePresentInPacakge: boolean, isFolderBasedDeployment: boolean, useWebDeploy: boolean, authType?: string): string;
21
+ export declare function getWebDeployArgumentsString(args: WebDeployArguments): Promise<string>;
22
+ export declare function shouldUseMSDeployTokenAuth(): boolean;
21
23
  /**
22
24
  * Gets the full path of MSDeploy.exe
23
25
  *
24
26
  * @returns string
25
27
  */
26
- export declare function getMSDeployFullPath(): Promise<any>;
28
+ export declare function getMSDeployFullPath(): Promise<string>;
27
29
  /**
28
30
  * 1. Checks if msdeploy during execution redirected any error to
29
31
  * error stream ( saved in error.txt) , display error to console
@@ -44,6 +46,7 @@ export interface WebDeployArguments {
44
46
  setParametersFile?: string;
45
47
  additionalArguments?: string;
46
48
  useWebDeploy?: boolean;
49
+ authType?: string;
47
50
  }
48
51
  export interface WebDeployResult {
49
52
  isSuccess: boolean;
@@ -9,8 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.getWebDeployErrorCode = exports.redirectMSDeployErrorToConsole = exports.getMSDeployFullPath = exports.getWebDeployArgumentsString = exports.getMSDeployCmdArgs = void 0;
13
- const Q = require("q");
12
+ exports.getWebDeployErrorCode = exports.redirectMSDeployErrorToConsole = exports.getMSDeployFullPath = exports.shouldUseMSDeployTokenAuth = exports.getWebDeployArgumentsString = exports.getMSDeployCmdArgs = void 0;
14
13
  const tl = require("azure-pipelines-task-lib/task");
15
14
  const fs = require("fs");
16
15
  const path = require("path");
@@ -22,7 +21,7 @@ const ERROR_FILE_NAME = "error.txt";
22
21
  *
23
22
  * @param webAppPackage Web deploy package
24
23
  * @param webAppName web App Name
25
- * @param publishingProfile Azure RM Connection Details
24
+ * @param profile Azure RM Connection Details
26
25
  * @param removeAdditionalFilesFlag Flag to set DoNotDeleteRule rule
27
26
  * @param excludeFilesFromAppDataFlag Flag to prevent App Data from publishing
28
27
  * @param takeAppOfflineFlag Flag to enable AppOffline rule
@@ -31,10 +30,11 @@ const ERROR_FILE_NAME = "error.txt";
31
30
  * @param additionalArguments Arguments provided by user
32
31
  * @param isParamFilePresentInPacakge Flag to check Paramter.xml file
33
32
  * @param isFolderBasedDeployment Flag to check if given web package path is a folder
33
+ * @param authType Type of authentication to use
34
34
  *
35
35
  * @returns string
36
36
  */
37
- function getMSDeployCmdArgs(webAppPackage, webAppName, publishingProfile, removeAdditionalFilesFlag, excludeFilesFromAppDataFlag, takeAppOfflineFlag, virtualApplication, setParametersFile, additionalArguments, isParamFilePresentInPacakge, isFolderBasedDeployment, useWebDeploy) {
37
+ function getMSDeployCmdArgs(webAppPackage, webAppName, profile, removeAdditionalFilesFlag, excludeFilesFromAppDataFlag, takeAppOfflineFlag, virtualApplication, setParametersFile, additionalArguments, isParamFilePresentInPacakge, isFolderBasedDeployment, useWebDeploy, authType) {
38
38
  var msDeployCmdArgs = " -verb:sync";
39
39
  var webApplicationDeploymentPath = (virtualApplication) ? webAppName + "/" + virtualApplication : webAppName;
40
40
  if (isFolderBasedDeployment) {
@@ -64,9 +64,9 @@ function getMSDeployCmdArgs(webAppPackage, webAppName, publishingProfile, remove
64
64
  }
65
65
  }
66
66
  }
67
- if (publishingProfile != null) {
68
- msDeployCmdArgs += ",ComputerName=\"'https://" + publishingProfile.publishUrl + "/msdeploy.axd?site=" + webAppName + "'\",";
69
- msDeployCmdArgs += "UserName=\"'" + publishingProfile.userName + "'\",Password=\"'" + publishingProfile.userPWD + "'\",AuthType=\"'Basic'\"";
67
+ if (profile != null) {
68
+ msDeployCmdArgs += `,ComputerName=\"'https://${profile.publishUrl}/msdeploy.axd?site=${webAppName}'\",`;
69
+ msDeployCmdArgs += `UserName=\"'${profile.userName}'\",Password=\"'${profile.userPWD}'\",AuthType=\"'${authType || "Basic"}'\"`;
70
70
  }
71
71
  if (isParamFilePresentInPacakge) {
72
72
  msDeployCmdArgs += " -setParam:name=\"'IIS Web Application Name'\",value=\"'" + webApplicationDeploymentPath + "'\"";
@@ -87,7 +87,7 @@ function getMSDeployCmdArgs(webAppPackage, webAppName, publishingProfile, remove
87
87
  if (!(removeAdditionalFilesFlag && useWebDeploy)) {
88
88
  msDeployCmdArgs += " -enableRule:DoNotDeleteRule";
89
89
  }
90
- if (publishingProfile != null) {
90
+ if (profile != null) {
91
91
  var userAgent = tl.getVariable("AZURE_HTTP_USER_AGENT");
92
92
  if (userAgent) {
93
93
  msDeployCmdArgs += ' -userAgent:' + userAgent;
@@ -190,12 +190,21 @@ function parseAdditionalArguments(additionalArguments) {
190
190
  }
191
191
  return parsedArgs;
192
192
  }
193
- function getWebDeployArgumentsString(webDeployArguments, publishingProfile) {
193
+ function getWebDeployArgumentsString(args) {
194
194
  return __awaiter(this, void 0, void 0, function* () {
195
- return getMSDeployCmdArgs(webDeployArguments.package.getPath(), webDeployArguments.appName, publishingProfile, webDeployArguments.removeAdditionalFilesFlag, webDeployArguments.excludeFilesFromAppDataFlag, webDeployArguments.takeAppOfflineFlag, webDeployArguments.virtualApplication, webDeployArguments.setParametersFile, webDeployArguments.additionalArguments, yield webDeployArguments.package.isMSBuildPackage(), webDeployArguments.package.isFolder(), webDeployArguments.useWebDeploy);
195
+ const profile = {
196
+ userPWD: args.password,
197
+ userName: args.userName,
198
+ publishUrl: args.publishUrl
199
+ };
200
+ return getMSDeployCmdArgs(args.package.getPath(), args.appName, profile, args.removeAdditionalFilesFlag, args.excludeFilesFromAppDataFlag, args.takeAppOfflineFlag, args.virtualApplication, args.setParametersFile, args.additionalArguments, yield args.package.isMSBuildPackage(), args.package.isFolder(), args.useWebDeploy, args.authType);
196
201
  });
197
202
  }
198
203
  exports.getWebDeployArgumentsString = getWebDeployArgumentsString;
204
+ function shouldUseMSDeployTokenAuth() {
205
+ return (tl.getVariable("USE_MSDEPLOY_TOKEN_AUTH") || "").toLowerCase() === "true";
206
+ }
207
+ exports.shouldUseMSDeployTokenAuth = shouldUseMSDeployTokenAuth;
199
208
  /**
200
209
  * Gets the full path of MSDeploy.exe
201
210
  *
@@ -204,65 +213,104 @@ exports.getWebDeployArgumentsString = getWebDeployArgumentsString;
204
213
  function getMSDeployFullPath() {
205
214
  return __awaiter(this, void 0, void 0, function* () {
206
215
  try {
207
- var msDeployInstallPathRegKey = "\\SOFTWARE\\Microsoft\\IIS Extensions\\MSDeploy";
208
- var msDeployLatestPathRegKey = yield getMSDeployLatestRegKey(msDeployInstallPathRegKey);
209
- var msDeployFullPath = yield getMSDeployInstallPath(msDeployLatestPathRegKey);
210
- msDeployFullPath = msDeployFullPath + "msdeploy.exe";
211
- return msDeployFullPath;
216
+ const msDeployInstallPathRegKey = "\\SOFTWARE\\Microsoft\\IIS Extensions\\MSDeploy";
217
+ const msDeployLatestPathRegKey = yield getMSDeployLatestRegKey(msDeployInstallPathRegKey);
218
+ return (yield getMSDeployInstallPath(msDeployLatestPathRegKey)) + "msdeploy.exe";
212
219
  }
213
220
  catch (error) {
214
221
  tl.debug(error);
215
- return path.join(__dirname, "MSDeploy3.6/MSDeploy3.6", "msdeploy.exe");
222
+ const subfolder = shouldUseMSDeployTokenAuth() ? "M229" : "M142";
223
+ return path.join(__dirname, "MSDeploy", subfolder, "MSDeploy3.6", "msdeploy.exe");
216
224
  }
217
225
  });
218
226
  }
219
227
  exports.getMSDeployFullPath = getMSDeployFullPath;
220
228
  function getMSDeployLatestRegKey(registryKey) {
221
- var defer = Q.defer();
222
- var regKey = new winreg({
223
- hive: winreg.HKLM,
224
- key: registryKey
225
- });
226
- regKey.keys(function (err, subRegKeys) {
227
- if (err) {
228
- defer.reject(tl.loc("UnabletofindthelocationofMSDeployfromregistryonmachineError", err));
229
- return;
230
- }
231
- var latestKeyVersion = 0;
232
- var latestSubKey;
233
- for (var index in subRegKeys) {
234
- var subRegKey = subRegKeys[index].key;
235
- var subKeyVersion = subRegKey.substr(subRegKey.lastIndexOf('\\') + 1, subRegKey.length - 1);
236
- if (!isNaN(subKeyVersion)) {
237
- var subKeyVersionNumber = parseFloat(subKeyVersion);
238
- if (subKeyVersionNumber > latestKeyVersion) {
239
- latestKeyVersion = subKeyVersionNumber;
240
- latestSubKey = subRegKey;
229
+ return new Promise((resolve, reject) => {
230
+ var regKey = new winreg({
231
+ hive: winreg.HKLM,
232
+ key: registryKey
233
+ });
234
+ regKey.keys(function (err, subRegKeys) {
235
+ if (err) {
236
+ reject(tl.loc("UnabletofindthelocationofMSDeployfromregistryonmachineError", err));
237
+ return;
238
+ }
239
+ var latestKeyVersion = 0;
240
+ var latestSubKey;
241
+ for (var index in subRegKeys) {
242
+ var subRegKey = subRegKeys[index].key;
243
+ var subKeyVersion = subRegKey.substr(subRegKey.lastIndexOf('\\') + 1, subRegKey.length - 1);
244
+ if (!isNaN(subKeyVersion)) {
245
+ var subKeyVersionNumber = parseFloat(subKeyVersion);
246
+ if (subKeyVersionNumber > latestKeyVersion) {
247
+ latestKeyVersion = subKeyVersionNumber;
248
+ latestSubKey = subRegKey;
249
+ }
241
250
  }
242
251
  }
243
- }
244
- if (latestKeyVersion < 3) {
245
- defer.reject(tl.loc("UnsupportedinstalledversionfoundforMSDeployversionshouldbeatleast3orabove", latestKeyVersion));
246
- return;
247
- }
248
- defer.resolve(latestSubKey);
252
+ if (latestKeyVersion < 3) {
253
+ reject(tl.loc("UnsupportedinstalledversionfoundforMSDeployversionshouldbeatleast3orabove", latestKeyVersion));
254
+ return;
255
+ }
256
+ resolve(latestSubKey);
257
+ });
249
258
  });
250
- return defer.promise;
251
259
  }
252
260
  function getMSDeployInstallPath(registryKey) {
253
- var defer = Q.defer();
254
- var regKey = new winreg({
255
- hive: winreg.HKLM,
256
- key: registryKey
261
+ return new Promise((resolve, reject) => {
262
+ var regKey = new winreg({
263
+ hive: winreg.HKLM,
264
+ key: registryKey
265
+ });
266
+ regKey.values(function (err, items) {
267
+ if (err) {
268
+ reject(tl.loc("UnabletofindthelocationofMSDeployfromregistryonmachineError", err));
269
+ }
270
+ if (shouldUseMSDeployTokenAuth()) {
271
+ const versionItem = items.find(item => item.name === "Version");
272
+ if (!versionItem) {
273
+ reject(tl.loc("MissingMSDeployVersionRegistryKey"));
274
+ }
275
+ const minimalSupportedVersion = "9.0.7225.0";
276
+ const version = versionItem.value;
277
+ tl.debug(`Installed MSDeploy Version: ${version}`);
278
+ // MSDeploy 9.0.7225.0 is the first version to support token auth
279
+ if (compareVersions(version, minimalSupportedVersion) < 0) {
280
+ reject(tl.loc("UnsupportedMSDeployVersion", version));
281
+ }
282
+ }
283
+ const installPathItem = items.find(item => item.name === "InstallPath");
284
+ if (!installPathItem) {
285
+ reject(tl.loc("MissingMSDeployInstallPathRegistryKey"));
286
+ }
287
+ resolve(installPathItem.value);
288
+ });
257
289
  });
258
- regKey.get("InstallPath", function (err, item) {
259
- if (err) {
260
- defer.reject(tl.loc("UnabletofindthelocationofMSDeployfromregistryonmachineError", err));
261
- return;
290
+ }
291
+ function compareVersions(version1, version2) {
292
+ if (version1 === version2) {
293
+ return 0;
294
+ }
295
+ const separator = ".";
296
+ const parts1 = version1.split(separator).map(Number);
297
+ const parts2 = version2.split(separator).map(Number);
298
+ const length = Math.min(parts1.length, parts2.length);
299
+ for (let i = 0; i < length; i++) {
300
+ if (parts1[i] > parts2[i]) {
301
+ return 1;
262
302
  }
263
- defer.resolve(item.value);
264
- });
265
- return defer.promise;
303
+ if (parts1[i] < parts2[i]) {
304
+ return -1;
305
+ }
306
+ }
307
+ if (parts1.length > parts2.length) {
308
+ return 1;
309
+ }
310
+ if (parts1.length < parts2.length) {
311
+ return -1;
312
+ }
313
+ return 0;
266
314
  }
267
315
  /**
268
316
  * 1. Checks if msdeploy during execution redirected any error to
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "azure-pipelines-tasks-webdeployment-common",
3
- "version": "4.230.0",
3
+ "version": "4.230.1",
4
4
  "description": "Common Lib for MSDeploy Utility",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+ssh://git@github.com/Microsoft/azure-pipelines-tasks.git"
8
8
  },
9
9
  "scripts": {
10
- "build": "node ../build-scripts/downloadArchive.js https://vstsagenttools.blob.core.windows.net/tools/7zip/1/7zip.zip ./7zip && node ../build-scripts/downloadArchive.js https://vstsagenttools.blob.core.windows.net/tools/MSDeploy/3.6/M142/MSDeploy.zip ./MSDeploy3.6 && node make.js"
10
+ "build": "pwsh build.ps1"
11
11
  },
12
12
  "author": "Microsoft Corporation",
13
13
  "license": "MIT",