gjw80
gjw80

Reputation: 1078

Bash script not outputting nohup.out + Jenkins

I have a bash script that I am calling from a build step in Jenkins. Within this bash script is a nohup command for calling a different script in the background, such as:

#!/bin/bash
nohup otherScript.sh &

After the build step completes I go to the path where the nohup.out should have been created, but there is nothing there. Any ideas on what is going on?

Upvotes: 1

Views: 6772

Answers (2)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200293

Quoting from man nohup:

If standard input is a terminal, redirect it from /dev/null. If standard output is a terminal, append output to nohup.out if possible, $HOME/nohup.out otherwise. If standard error is a terminal, redirect it to standard output. To save output to FILE, use nohup COMMAND > FILE.

Running the command from Jenkins probably means that STDOUT is not a terminal, thus nohup.out is not created. As gareth_bowles already suggested, you should redirect the output to a file with a defined path:

nohup script.sh >/path/to/output.log 2>&1 &

Upvotes: 3

gareth_bowles
gareth_bowles

Reputation: 21130

You should make sure that the output goes into your build's workspace. This will avoid permission problems with other directories.

nohup otherScript.sh > $WORKSPACE/scriptOutput.txt 2>&1 &

Upvotes: 6

Related Questions