Background:
Here is a snippet of code: In this example, this makefile will build:
def build() {
command = """ #!/bin/bash
ls -la
make clean || :
make all -k 2>&1
"""
try {
result = sh(returnStdout: true, script: command)
}
}
Let's assume that the make was unsuccessful.
We can create a failed build by adding a -z flag.
def build_fail() {
command_fail = """ #!/bin/bash
ls -la
make clean || :
make all -k -z 2>&1
"""
try {
result_fail = sh(returnStdout: true, script: command_fail)
println (result_fail)
}
catch (Exception e) {
println (e)
}
// It will return back Jenkins error code 2 only, but I need more details
}
The issue
When running the second snippet of code, I need to be able to see not just the error code of successful or not successful, but the information along with it.
I need
- To see where the makefile is failing in stdout and
- Write the message to a file
I can see that the build is failing because of the -z flag but it's not actually being printed from stdout, it's from the shell script. Eg:
What didn't work
Redirecting stderr to stdout (snippet 2 doesn't work)
Capturing using script fileName... exit I try to capture the output by enclosing it in
script fileName...exit
try {
script output.txt
result_fail = sh(returnStdout: true, script: command_fail)
exit
}
The output was:
It does not describe what is actually happening inside the process.
- Pipes and Tee
I tried using pipes and Tees from answers around stackoverflow and other stackexchange site but when redirecting input to files and doing cat fileName, they would be empty.