Jenkins how to print output of command to file even if command fails?

From what i’ve read, Jenkins logging seems to be done in JVM, where it uses Java’s log util class. This is a problem because one of the commands that is run logs nearly 90MB worth of memory. I could technically increase the JVM size, but i couldn’t get that to work, AND i would prefer writing this long log to file instead.

let’s say i have a command like xcodebuild and this generates 90MB worth of logging. i’ve instead done this on my jenkins build script:

xcodebuild abc > my_output.txt

However, it seems that my_output.txt does not actually exist if the build failed. This is contrary to how regular bash seems to work. Hmm…

Is there any clever workaround, so that even if the command fails (and logs SOME stuff) that the file is created anyways?

i just want to be able to mail the last 20 lines of the log file to myself upon if the jenkins task failed. But because the file isn’t created, the log is gone forever

Source: bash

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.