-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathoc-setup-task.ts
34 lines (30 loc) · 1.41 KB
/
oc-setup-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
/*-----------------------------------------------------------------------------------------------
* 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 { 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: string = task.getInput('version');
const agentOS: string = getAgentOsName(task.getPlatform());
const proxy: string = task.getInput('proxy');
const binaryVersion: BinaryVersion = convertStringToBinaryVersion(version);
const ocBinary: FindBinaryStatus = await InstallHandler.installOc(binaryVersion, agentOS, false, proxy);
if (ocBinary.found === false) {
return Promise.reject(new Error(getReason(ocBinary)));
}
InstallHandler.addOcToPath(ocBinary.path, agentOS);
await auth.createKubeConfig(ocBinary.path, agentOS);
}
run()
.then(() => {
task.setResult(
task.TaskResult.Succeeded,
'oc successfully installed and configured'
);
})
.catch((err: Error) => {
task.setResult(task.TaskResult.Failed, err.message);
});