execute bash commands in automations
This commit is contained in:
parent
04cdb7fb8b
commit
7c4ec2f23a
|
@ -4,6 +4,7 @@ const createRow = require("./steps/createRow")
|
||||||
const updateRow = require("./steps/updateRow")
|
const updateRow = require("./steps/updateRow")
|
||||||
const deleteRow = require("./steps/deleteRow")
|
const deleteRow = require("./steps/deleteRow")
|
||||||
const executeScript = require("./steps/executeScript")
|
const executeScript = require("./steps/executeScript")
|
||||||
|
const bash = require("./steps/bash")
|
||||||
const executeQuery = require("./steps/executeQuery")
|
const executeQuery = require("./steps/executeQuery")
|
||||||
const outgoingWebhook = require("./steps/outgoingWebhook")
|
const outgoingWebhook = require("./steps/outgoingWebhook")
|
||||||
const env = require("../environment")
|
const env = require("../environment")
|
||||||
|
@ -21,6 +22,7 @@ const BUILTIN_ACTIONS = {
|
||||||
DELETE_ROW: deleteRow.run,
|
DELETE_ROW: deleteRow.run,
|
||||||
OUTGOING_WEBHOOK: outgoingWebhook.run,
|
OUTGOING_WEBHOOK: outgoingWebhook.run,
|
||||||
EXECUTE_SCRIPT: executeScript.run,
|
EXECUTE_SCRIPT: executeScript.run,
|
||||||
|
EXECUTE_BASH: bash.run,
|
||||||
EXECUTE_QUERY: executeQuery.run,
|
EXECUTE_QUERY: executeQuery.run,
|
||||||
}
|
}
|
||||||
const BUILTIN_DEFINITIONS = {
|
const BUILTIN_DEFINITIONS = {
|
||||||
|
@ -32,6 +34,7 @@ const BUILTIN_DEFINITIONS = {
|
||||||
OUTGOING_WEBHOOK: outgoingWebhook.definition,
|
OUTGOING_WEBHOOK: outgoingWebhook.definition,
|
||||||
EXECUTE_SCRIPT: executeScript.definition,
|
EXECUTE_SCRIPT: executeScript.definition,
|
||||||
EXECUTE_QUERY: executeQuery.definition,
|
EXECUTE_QUERY: executeQuery.definition,
|
||||||
|
EXECUTE_BASH: bash.definition,
|
||||||
}
|
}
|
||||||
|
|
||||||
let MANIFEST = null
|
let MANIFEST = null
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
const scriptController = require("../../api/controllers/script")
|
||||||
|
const { execSync } = require("child_process")
|
||||||
|
const { processStringSync } = require("@budibase/string-templates")
|
||||||
|
|
||||||
|
module.exports.definition = {
|
||||||
|
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"],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.run = async function ({ inputs, context }) {
|
||||||
|
if (inputs.code == null) {
|
||||||
|
return {
|
||||||
|
stdout: "Budibase bash automation failed: Invalid inputs",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const command = processStringSync(inputs.code, context)
|
||||||
|
const stdout = execSync(command, { timeout: 1000 })
|
||||||
|
return {
|
||||||
|
stdout,
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err)
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
response: err,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
const scriptController = require("../../api/controllers/script")
|
const scriptController = require("../../api/controllers/script")
|
||||||
|
|
||||||
module.exports.definition = {
|
module.exports.definition = {
|
||||||
name: "Scripting",
|
name: "JS Scripting",
|
||||||
tagline: "Execute JavaScript Code",
|
tagline: "Execute JavaScript Code",
|
||||||
icon: "ri-terminal-box-line",
|
icon: "ri-terminal-box-line",
|
||||||
description: "Run a piece of JavaScript code in your automation",
|
description: "Run a piece of JavaScript code in your automation",
|
||||||
|
|
Loading…
Reference in New Issue