-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathoc-exec-task.ts
38 lines (34 loc) · 1.62 KB
/
oc-exec-task.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
/*-----------------------------------------------------------------------------------------------
* Copyright (c) Red Hat, Inc. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*-----------------------------------------------------------------------------------------------*/
import task = require('azure-pipelines-task-lib/task');
import { RunnerHandler } from './oc-exec.ts';
import { InstallHandler } from './oc-install.ts';
import * as auth from './oc-auth.ts';
import { BinaryVersion, convertStringToBinaryVersion, FindBinaryStatus, getAgentOsName, getReason } from './utils/exec_helper.ts';
async function run(): Promise<void> {
const version = task.getInput('version');
const argLine = task.getInput('cmd');
const ignoreFlag: boolean = task.getBoolInput('ignoreFlag');
const useLocalOc: boolean = task.getBoolInput('useLocalOc');
const proxy: string = task.getInput('proxy');
const agentOS = getAgentOsName(task.getPlatform());;
const binaryVersion: BinaryVersion = convertStringToBinaryVersion(version);
const ocBinary: FindBinaryStatus = await InstallHandler.installOc(binaryVersion, agentOS, useLocalOc, proxy);
if (ocBinary.found === false) {
return Promise.reject(new Error(getReason(ocBinary)));
}
await auth.createKubeConfig(ocBinary.path, agentOS);
await RunnerHandler.execOc(ocBinary.path, argLine, ignoreFlag);
}
run()
.then(() => {
task.setResult(
task.TaskResult.Succeeded,
'oc command successfully executed.'
);
})
.catch((err: Error) => {
task.setResult(task.TaskResult.Failed, err.message);
});