jobber icon indicating copy to clipboard operation
jobber copied to clipboard

Question/Bug: how does one get the stderr output?

Open Adnn opened this issue 4 years ago • 1 comments

I am trying to capture both stderr and stdout of my job, to output to stdout. (I am yet another Docker user ; )

I could not find instructions in the current doc, but have been following this comment: https://github.com/dshearer/jobber/issues/182#issuecomment-426403233

Now my jobber file is as follows

version: 1.4

resultSinks:
  - &stdoutSink
    type: stdout
    data: [stdout, stderr]

jobs:
  ExampleJob:
    cmd: /jobbercommand.sh
    time: '*/5 * * * * *'
    notifyOnSuccess: [*stdoutSink]
    notifyOnError: [*stdoutSink]

jobbercommand.sh simply run a python3 scripts which outputs two different lines, one to stdout, one to stderr. In the current terminal output, I can only see the output the script made to stdout.

jobberuser: /jobbercommand.sh {
	"fate": 0,
	"job": {
		"command": "/jobbercommand.sh",
		"name": "ExampleJob",
		"status": "Good",
		"time": "*/5 * * * * *"
	},
	"startTime": 1624608890,
	"stderr": "Stdout message from Python.\n",
	"stdout": "Stdout message from Python.\n",
	"succeeded": true,
	"user": "jobberuser",
	"version": "1.4"
}

(This got me thinking for hours that jobber was not working, since my initial script only wrote to stderr: all I saw was a "blank" output from jobber, thinking the script never run and not having any message to help me debug appart from the return code).

Is it not the way to write a jobber file which captures both stderr and stdout and redirect the result to current terminal stdout?

Thank you for reading!


Edit: for completeness, the Python script

#!/usr/bin/env python3

import sys

if __name__ == "__main__":
    print("Stdout message from Python.")
    print("Stderr message from Python.", file=sys.stderr)

Adnn avatar Jun 25 '21 08:06 Adnn

I am also having this problem trying to capture the output of my jobber script, which at this point is just an echo command to make sure I can get it to work. The format of the .jobber file in the documentation is a bit different than what's actually in the file when I enter a bash terminal inside my docker container. This is what I set up initially, which I can confirm runs:

[jobs]
- name: ExampleScript
  cmd: /home/jobberuser/example-scheduled-task.sh
  time: '*'

Below is an attempt to separate out the resultsSinks into their own section. This fails with a "Failed to parse 'jobs' section: yaml: unmarshal errors: line 6: cannot unmarshal !!seq into bool"

[jobs]
- name: ExampleScript
  cmd: /home/jobberuser/example-scheduled-task.sh
  time: '*'
  notifyOnSuccess:
    - *stdoutSink
- resultSinks:
    - &stdoutSink
      type: stdout
      data:
        - stdout
        - stderr

The documentation seems to suggest that I don't need to use a separate resultSinks section, but the below fails with a similar error:

jobs:
- name: ExampleScript
  cmd: /home/jobberuser/example-scheduled-task.sh
  time: '*'
  notifyOnSuccess:
    - type: stdout
      data:
        - stdout
        - stderr

Am I getting the syntax wrong?

Pigpocket avatar Jul 12 '21 06:07 Pigpocket