Created command execution custom plugin
Signed-off-by: Mani Marothu <manikumar.1215@gmail.com>
This commit is contained in:
parent
3004c289c7
commit
8f5cf49093
3 changed files with 38 additions and 0 deletions
32
examples/template/template-command-execute.yaml
Normal file
32
examples/template/template-command-execute.yaml
Normal file
|
@ -0,0 +1,32 @@
|
|||
apiVersion: scaffolder.backstage.io/v1beta3
|
||||
kind: Template
|
||||
metadata:
|
||||
name: deploy-resources
|
||||
title: Deploy Resources
|
||||
description: Deploy Resource to Kubernetes
|
||||
spec:
|
||||
owner: guest
|
||||
type: service
|
||||
# these are the steps which are rendered in the frontend with the form input
|
||||
parameters:
|
||||
- title: file name
|
||||
properties:
|
||||
path:
|
||||
type: string
|
||||
description: file name
|
||||
default: cm.yaml
|
||||
steps:
|
||||
- id: wait-for-few-mins
|
||||
name: Wait to run next step
|
||||
action: debug:wait
|
||||
input:
|
||||
seconds: 10
|
||||
- id: shell-command
|
||||
name: Run Command
|
||||
action: cnoe:command:execute
|
||||
input:
|
||||
command: curl
|
||||
arguments: [
|
||||
'https://fake-json-api.mock.beeceptor.com/users'
|
||||
]
|
||||
|
|
@ -2,6 +2,7 @@ import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
|
|||
import { executeShellCommand } from '@backstage/plugin-scaffolder-node';
|
||||
|
||||
export const executeCommand = () => {
|
||||
|
||||
return createTemplateAction<{
|
||||
command: string;
|
||||
arguments?: string[];
|
||||
|
@ -36,6 +37,8 @@ export const executeCommand = () => {
|
|||
if (!command) {
|
||||
throw new Error('The command must be provided.');
|
||||
}
|
||||
|
||||
ctx.logger.info("Running command "+command+" "+commandArgs.join(' '));
|
||||
|
||||
// Execute the shell command with optional arguments
|
||||
await executeShellCommand({
|
||||
|
@ -43,6 +46,7 @@ export const executeCommand = () => {
|
|||
args: commandArgs,
|
||||
logStream: ctx.logStream,
|
||||
});
|
||||
ctx.logger.info('Command executed successfully!');
|
||||
},
|
||||
});
|
||||
};
|
||||
|
|
|
@ -11,6 +11,7 @@ import { getRootLogger } from '@backstage/backend-common';
|
|||
import { createKubernetesApply } from './k8s-apply';
|
||||
import { createSanitizeResource } from './sanitize';
|
||||
import { createVerifyDependency } from './verify';
|
||||
import { executeCommand } from './execute-command';
|
||||
|
||||
export const cnoeScaffolderActions = createBackendModule({
|
||||
pluginId: 'scaffolder',
|
||||
|
@ -37,6 +38,7 @@ export const cnoeScaffolderActions = createBackendModule({
|
|||
createKubernetesApply(config),
|
||||
createSanitizeResource(),
|
||||
createVerifyDependency(),
|
||||
executeCommand()
|
||||
);
|
||||
},
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue