Skip to content

Commit

Permalink
Created command execution custom plugin
Browse files Browse the repository at this point in the history
Signed-off-by: Mani Marothu <[email protected]>
  • Loading branch information
mmaroth committed Sep 18, 2024
1 parent e1c62df commit 2b78c2a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
32 changes: 32 additions & 0 deletions examples/template/template-command-execute.yaml
Original file line number Diff line number Diff line change
@@ -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'
]

4 changes: 4 additions & 0 deletions packages/backend/src/plugins/execute-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down Expand Up @@ -36,13 +37,16 @@ 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({
command: command,
args: commandArgs,
logStream: ctx.logStream,
});
ctx.logger.info('Command executed successfully!');
},
});
};
2 changes: 2 additions & 0 deletions packages/backend/src/plugins/scaffolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -37,6 +38,7 @@ export const cnoeScaffolderActions = createBackendModule({
createKubernetesApply(config),
createSanitizeResource(),
createVerifyDependency(),
executeCommand()
);
},
});
Expand Down

0 comments on commit 2b78c2a

Please sign in to comment.