From d82d4c8f2cb747152c91da6cc6658e3977955f2a Mon Sep 17 00:00:00 2001 From: Brooks Swinnerton Date: Fri, 30 Jul 2021 11:42:16 -0400 Subject: [PATCH] Capture output of stdout and stderr to Actions --- action.yml | 5 +++++ main.js | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index c35442d..b11eac6 100644 --- a/action.yml +++ b/action.yml @@ -31,6 +31,11 @@ inputs: sudo: description: Set to "true" if root is required for running your playbook required: false +outputs: + stdout: + description: The captured output of stdout from the Ansible Playbook run + stderr: + description: The captured output of stderr from the Ansible Playbook run runs: using: node12 main: main.js diff --git a/main.js b/main.js index 81e200b..fefb308 100644 --- a/main.js +++ b/main.js @@ -81,7 +81,17 @@ async function main() { process.env.ANSIBLE_FORCE_COLOR = "True" - await exec.exec(cmd.join(' ')) + const execOptions = {}; + execOptions.listeners = { + stdout: (data: Buffer) => { + core.setOutput('stdout', data.toString()); + }, + stderr: (data: Buffer) => { + core.setOutput('stderr', data.toString()); + } + }; + + await exec.exec(cmd.join(' '), execOptions) } catch (error) { core.setFailed(error.message) }