Consolidate stdout and stderr into single output

This commit is contained in:
Brooks Swinnerton 2021-07-30 21:50:09 -04:00
parent 7e6cacac83
commit d8a8e9121d
No known key found for this signature in database
GPG Key ID: 72743B7DE552E25A
2 changed files with 6 additions and 10 deletions

View File

@ -32,10 +32,8 @@ inputs:
description: Set to "true" if root is required for running your playbook description: Set to "true" if root is required for running your playbook
required: false required: false
outputs: outputs:
stdout: output:
description: The captured output of stdout from the Ansible Playbook run description: The captured output of both stdout and stderr from the Ansible Playbook run
stderr:
description: The captured output of stderr from the Ansible Playbook run
runs: runs:
using: node12 using: node12
main: main.js main: main.js

10
main.js
View File

@ -81,21 +81,19 @@ async function main() {
process.env.ANSIBLE_FORCE_COLOR = "True" process.env.ANSIBLE_FORCE_COLOR = "True"
let stdout = '' let output = ''
let stderr = ''
const execOptions = {} const execOptions = {}
execOptions.listeners = { execOptions.listeners = {
stdout: function(data) { stdout: function(data) {
stdout += data.toString() output += data.toString()
}, },
stderr: function(data) { stderr: function(data) {
stderr += data.toString() output += data.toString()
} }
} }
await exec.exec("ansible-playbook", cmd, execOptions) await exec.exec("ansible-playbook", cmd, execOptions)
core.setOutput('stdout', stdout) core.setOutput('output', output)
core.setOutput('stderr', stderr)
} catch (error) { } catch (error) {
core.setFailed(error.message) core.setFailed(error.message)
} }