1
0
Fork 0
mirror of synced 2024-07-08 15:56:23 +12:00
budibase/packages/server/src/automations/steps/bash.js

63 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-05-27 22:11:44 +12:00
const { execSync } = require("child_process")
const { processStringSync } = require("@budibase/string-templates")
exports.definition = {
2021-05-27 22:11:44 +12:00
name: "Bash Scripting",
tagline: "Execute a bash command",
icon: "ri-terminal-box-line",
description: "Run a bash script",
type: "ACTION",
stepId: "EXECUTE_BASH",
inputs: {},
schema: {
inputs: {
properties: {
code: {
type: "string",
customType: "code",
title: "Code",
},
},
required: ["code"],
},
outputs: {
properties: {
stdout: {
type: "string",
description: "Standard output of your bash command or script.",
},
},
},
required: ["stdout"],
},
}
exports.run = async function ({ inputs, context }) {
2021-05-27 22:11:44 +12:00
if (inputs.code == null) {
return {
stdout: "Budibase bash automation failed: Invalid inputs",
}
}
try {
const command = processStringSync(inputs.code, context)
let stdout
try {
stdout = execSync(command, { timeout: 500 })
} catch (err) {
stdout = err.message
}
2021-05-27 22:11:44 +12:00
return {
stdout,
}
} catch (err) {
console.error(err)
return {
success: false,
response: err,
}
}
}