Create execute-command.ts
Added Execute command Signed-off-by: Mani Marothu <manikumar.1215@gmail.com>
This commit is contained in:
parent
5f3a54f571
commit
3004c289c7
1 changed files with 48 additions and 0 deletions
48
packages/backend/src/plugins/execute-command.ts
Normal file
48
packages/backend/src/plugins/execute-command.ts
Normal file
|
@ -0,0 +1,48 @@
|
|||
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
|
||||
import { executeShellCommand } from '@backstage/plugin-scaffolder-node';
|
||||
|
||||
export const executeCommand = () => {
|
||||
return createTemplateAction<{
|
||||
command: string;
|
||||
arguments?: string[];
|
||||
}>({
|
||||
id: 'cnoe:command:execute',
|
||||
schema: {
|
||||
input: {
|
||||
type: 'object',
|
||||
required: ['command'],
|
||||
properties: {
|
||||
command: {
|
||||
type: 'string',
|
||||
title: 'Command to run',
|
||||
description: 'Command to execute',
|
||||
},
|
||||
arguments: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string',
|
||||
},
|
||||
title: 'Command Arguments',
|
||||
description: 'Command arguments list',
|
||||
},
|
||||
},
|
||||
},
|
||||
output: {},
|
||||
},
|
||||
async handler(ctx) {
|
||||
const command = ctx.input.command;
|
||||
const commandArgs = ctx.input.arguments || [];
|
||||
|
||||
if (!command) {
|
||||
throw new Error('The command must be provided.');
|
||||
}
|
||||
|
||||
// Execute the shell command with optional arguments
|
||||
await executeShellCommand({
|
||||
command: command,
|
||||
args: commandArgs,
|
||||
logStream: ctx.logStream,
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
Loading…
Reference in a new issue