-
Notifications
You must be signed in to change notification settings - Fork 14
/
base.ts
54 lines (44 loc) · 1.52 KB
/
base.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
/// <reference path="typings/globals/node/index.d.ts" />
"use strict"
import * as Q from 'q';
import * as tl from 'vsts-task-lib/task';
import { ToolRunner } from 'vsts-task-lib/toolrunner';
export class BaseCommand {
subCommand : string;
multilineArgs : string;
binary: string;
constructor(binary: string) {
this.subCommand = tl.getInput('subCommand');
this.multilineArgs = tl.getInput('arguments');
this.binary = binary;
}
checkOSType() {
let isWin = tl.osType().match(/^Win/);
if (isWin) {
tl.setResult(tl.TaskResult.Failed, "This task does not work for Windows agent")
throw "This task does not work for Windows agent."
}
}
exec() {
this.checkOSType();
this.execCommand();
}
async execCommand() {
let binarycmd = tl.which(this.binary, true);
let binary = tl.tool(binarycmd);
binary.arg(this.subCommand);
if (this.multilineArgs) {
this.multilineArgs.split(/\s+/).map(function (x) { binary.arg(x) });
}
try {
let result = binary.execSync();
if (result.code != 0) {
throw result.error;
}
tl.setResult(tl.TaskResult.Succeeded, `${this.binary} command success.`);
} catch (err) {
tl.setResult(tl.TaskResult.Failed, err);
throw `Failed to execute ${this.binary} command.`;
}
}
}