Merge "Nexus retirement CI job clean up"
[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 # Generate gdb-command script to output vpp stack traceback from core files.
23 gdb_cmdfile="/tmp/gdb-commands"
24 cat >$gdb_cmdfile <<'__END__'
25 # Usage:
26 # gdb $BINFILE $CORE -ex 'source -v gdb-commands' -ex quit
27
28 set pagination off
29 thread apply all bt
30
31 define printstack
32   set $i=0
33   while $i < 15
34       frame $i
35       x/i $pc
36       info locals
37       info reg
38       set $i = $i + 1
39   end
40 end
41 thread apply all printstack
42
43 # info proc mappings
44
45 __END__
46
47 STACKTRACE=""
48 # Returns stacktrace filename in STACKTRACE
49 generate_vpp_stacktrace_and_delete_core() {
50     local corefile="$1"
51     echo "Uncompressing core file $file"
52     gunzip "$corefile"
53     corefile="${corefile::(-3)}"
54     if grep -qe 'debug' <<< "$WORKSPACE" ; then
55         local binfile="$WORKSPACE/build-root/install-vpp_debug-native/vpp/bin/vpp"
56     else
57         local binfile="$WORKSPACE/build-root/install-vpp-native/vpp/bin/vpp"
58     fi
59
60     echo "Generating stack trace from core file: $corefile"
61     STACKTRACE="${corefile}.stacktrace"
62     gdb "$binfile" $corefile -ex 'source -v /tmp/gdb-commands' -ex quit > $STACKTRACE
63     # remove the core to save space
64     echo "Removing core file: $corefile"
65     rm -f "$corefile"
66     # Dump stacktrace to console log
67     if [ -f "$STACKTRACE" ] ; then
68         echo -e "\n=====[ $STACKTRACE ]=====\n$(cat $STACKTRACE)\n=====[ $STACKTRACE ]=====\n"
69         gzip "$STACKTRACE"
70     else
71         echo "Stacktrace file not generated!"
72         STACKTRACE=""
73     fi
74 }
75
76 mkdir -p "$WS_ARCHIVES_DIR"
77
78 # generate stack trace for VPP core files for upload instead of core file.
79 if [ -d "$WORKSPACE/build-root" ] ; then
80     for file in $(find $WS_ARCHIVES_DIR -type f -name 'core*.gz') ; do
81         generate_vpp_stacktrace_and_delete_core $file
82     done
83 fi
84
85 # Remove any socket files in archive
86 find $WS_ARCHIVES_DIR -type s -exec rm -rf {} \;
87
88 echo "Workspace archived artifacts:"
89 ls -alR $WS_ARCHIVES_DIR