I have a build bash script running unde开发者_JAVA百科r Hudson build system, which writes its own log file. However, Hudson captures all the stdout and stderr of the build script it executes and displays it as the "console output" of the build. Furthermore, this output is saved in the build history.
How can I access this "console output" from within the script itself? I'd like to 1) save it as log together with the artifacts; 2) attach it to the notification email. Thanks
- It is saved along with the artifacts (the
log
file in top-level of build's directory, i.e.jobs/
jobname/builds/
buildid/log
). - It is automatically added to the email hudson sends, though truncated from begining.
If you need to get it anywhere else, there are two options:
You can have to wrap the script in a block and pipe it's output through tee. So you'd convert:
#!/bin/sh make this make that
to:
#!/bin/bash { make this make that } 2>&1 | tee output # Now the output is in file 'output' while Hudson did see it.
Unfortunately I am not sure how to force line-buffering in
tee
so the real-time log printing works in Hudson (at least my cygwin version does not mention-u
option).You could use the Groovy plugin and/or Groovy Postbuild plugin to access the internal API. The "system" groovy script in build step and the post-build groovy script both have access to the build object (though in slightly different way) of type hudson.model.AbstractBuild and from that you can get the content of the console using the hudson.model.Run#getLog(int) method.
To force line-buffering in tee, just start the program with unbuffer {command}
which is part of the expect
package. Another alternative to unbuffer
is to use stdbuf -eL -oL {command}
精彩评论