summaryrefslogtreecommitdiff
path: root/jenkins-helpers.sh
diff options
context:
space:
mode:
Diffstat (limited to 'jenkins-helpers.sh')
-rw-r--r--jenkins-helpers.sh21
1 files changed, 21 insertions, 0 deletions
diff --git a/jenkins-helpers.sh b/jenkins-helpers.sh
index 83f950ae..b196edca 100644
--- a/jenkins-helpers.sh
+++ b/jenkins-helpers.sh
@@ -1302,3 +1302,24 @@ EOF
run_step_prev_step="$pretty_step"
}
+
+# Print Python style traceback from a trap EXIT
+# More readable version of running "caller"
+print_traceback ()
+{
+ echo "ERROR Traceback (most recent call last):"
+ # Show most recent calls last
+ # >=1 to skip the trap handler entry
+ # Start from end-2 to skip the top level "main" entry
+ # which isn't useful
+ for (( i=${#FUNCNAME[@]}-2 ; i>=1 ; i-- )) ; do
+ source_file=${BASH_SOURCE[$i+1]}
+ line_no=${BASH_LINENO[$i]}
+ echo " File: $source_file, line $line_no"
+ # Remove leading whitespace to keep indentation readable
+ echo " $(sed -e "${line_no}!d" -e 's/^[[:space:]]*//' "$source_file")"
+ done
+ # We don't know the line number of the exit itself when we trap EXIT
+ echo " File: ${BASH_SOURCE[0]}, line ${BASH_LINENO[0]}"
+ echo " (trap handler, 'exit' call line is unknown)"
+}