Fix: Robot Framework logging
[ci-management.git] / jjb / scripts / post_build_deploy_archives.sh
1 #!/bin/bash
2
3 # Copyright (c) 2021 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 echo "---> jjb/scripts/post_build_deploy_archives.sh"
17
18 set +e  # Do not affect the build result if some part of archiving fails.
19 WS_ARCHIVES_DIR="$WORKSPACE/archives"
20 BUILD_ENV_LOG="$WS_ARCHIVES_DIR/_build-enviroment-variables.log"
21
22 if curl --output robot-plugin.zip "$BUILD_URL/robot/report/*zip*/robot-plugin.zip"; then
23     unzip -d ./archives robot-plugin.zip
24 fi
25
26 # Generate gdb-command script to output vpp stack traceback from core files.
27 gdb_cmdfile="/tmp/gdb-commands"
28 cat >$gdb_cmdfile <<'__END__'
29 # Usage:
30 # gdb $BINFILE $CORE -ex 'source -v gdb-commands' -ex quit
31
32 set pagination off
33 thread apply all bt
34
35 define printstack
36   set $i=0
37   while $i < 15
38       frame $i
39       x/i $pc
40       info locals
41       info reg
42       set $i = $i + 1
43   end
44 end
45 thread apply all printstack
46
47 # info proc mappings
48
49 __END__
50
51 STACKTRACE=""
52 # Returns stacktrace filename in STACKTRACE
53 generate_vpp_stacktrace_and_delete_core() {
54     local corefile="$1"
55     echo "Uncompressing core file $file"
56     gunzip "$corefile"
57     corefile="${corefile::(-3)}"
58     if grep -qe 'debug' <<< "$WORKSPACE" ; then
59         local binfile="$WORKSPACE/build-root/install-vpp_debug-native/vpp/bin/vpp"
60     else
61         local binfile="$WORKSPACE/build-root/install-vpp-native/vpp/bin/vpp"
62     fi
63
64     echo "Generating stack trace from core file: $corefile"
65     STACKTRACE="${corefile}.stacktrace"
66     gdb "$binfile" $corefile -ex 'source -v /tmp/gdb-commands' -ex quit > $STACKTRACE
67     # remove the core to save space
68     echo "Removing core file: $corefile"
69     rm -f "$corefile"
70     # Dump stacktrace to console log
71     if [ -f "$STACKTRACE" ] ; then
72         echo -e "\n=====[ $STACKTRACE ]=====\n$(cat $STACKTRACE)\n=====[ $STACKTRACE ]=====\n"
73         gzip "$STACKTRACE"
74     else
75         echo "Stacktrace file not generated!"
76         STACKTRACE=""
77     fi
78 }
79
80 mkdir -p "$WS_ARCHIVES_DIR"
81
82 # generate stack trace for VPP core files for upload instead of core file.
83 if [ -d "$WORKSPACE/build-root" ] ; then
84     for file in $(find $WS_ARCHIVES_DIR -type f -name 'core*.gz') ; do
85         generate_vpp_stacktrace_and_delete_core $file
86     done
87 fi
88
89 # Remove any socket files in archive
90 find $WS_ARCHIVES_DIR -type s -exec rm -rf {} \;
91
92 echo "Workspace archived artifacts:"
93 ls -alR $WS_ARCHIVES_DIR