-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
vstestplatformtoolinstaller.ts
79 lines (66 loc) · 3.2 KB
/
vstestplatformtoolinstaller.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import * as tl from 'azure-pipelines-task-lib/task';
import * as os from 'os';
import * as path from 'path';
import * as perf from 'performance-now';
import * as ci from './cieventlogger';
import * as constants from './constants';
import { NugetFeedInstaller } from './nugetfeedinstaller';
import { NetworkShareInstaller } from './networkshareinstaller';
let startTime: number;
// First function to be invoke starting the installation
async function startInstaller() {
try {
console.log(tl.loc('StartingInstaller'));
console.log('==============================================================================');
const osPlat: string = os.platform();
ci.addToConsolidatedCi('operatingSystem', osPlat);
ci.addToConsolidatedCi('result', constants.installationStatusFailed);
// Fail the task if os is not windows
if (osPlat !== 'win32') {
ci.addToConsolidatedCi('failureReason', constants.unsupportedOS);
tl.setResult(tl.TaskResult.Failed, tl.loc('OnlyWindowsOsSupported'));
return;
}
// Read task inputs
const packageFeedSelectorInput = tl.getInput(constants.packageFeedSelector, true);
const versionSelectorInput = tl.getInput(constants.versionSelector, false);
const testPlatformVersion = tl.getInput(constants.testPlatformVersion, false);
const networkSharePath = tl.getInput(constants.netShare, false);
const username = tl.getInput(constants.username, false);
const password = tl.getInput(constants.password, false);
const packageSource = constants.defaultPackageSource;
ci.addToConsolidatedCi('packageFeedSelectorInput', packageFeedSelectorInput);
tl.debug(`Selected package feed: ${packageFeedSelectorInput}`);
switch (packageFeedSelectorInput.toLowerCase()) {
case 'nugetorg':
tl.debug('Going via nuget org download flow.');
await new NugetFeedInstaller()
.installVsTestPlatformToolFromSpecifiedFeed(packageSource, testPlatformVersion, versionSelectorInput, null);
break;
case 'customfeed':
tl.debug('Going via custom feed download flow.');
await new NugetFeedInstaller()
.installVsTestPlatformToolFromCustomFeed(packageSource, versionSelectorInput, testPlatformVersion, username, password);
break;
case 'netshare':
tl.debug('Going via net share copy flow.');
await new NetworkShareInstaller().installVsTestPlatformToolFromNetworkShare(networkSharePath);
break;
}
} catch (error) {
ci.publishEvent('Completed', { isSetupSuccessful: 'false' } );
tl.setResult(tl.TaskResult.Failed, error);
return;
}
ci.addToConsolidatedCi('result', constants.installationStatusSucceeded);
}
// Execution start
tl.setResourcePath(path.join(__dirname, 'task.json'));
startTime = perf();
startInstaller().then(() => {
ci.addToConsolidatedCi('executionTime', perf() - startTime);
ci.fireConsolidatedCi();
}).catch(() => {
ci.addToConsolidatedCi('executionTime', perf() - startTime);
ci.fireConsolidatedCi();
});