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:
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
16 echo "---> jjb/scripts/post_build_deploy_archives.sh"
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"
22 # Generate gdb-command script to output vpp stack traceback from core files.
23 gdb_cmdfile="/tmp/gdb-commands"
24 cat >$gdb_cmdfile <<'__END__'
26 # gdb $BINFILE $CORE -ex 'source -v gdb-commands' -ex quit
41 thread apply all printstack
48 # Returns stacktrace filename in STACKTRACE
49 generate_vpp_stacktrace_and_delete_core() {
51 if grep -qe 'debug' <<< "$WORKSPACE" ; then
52 local binfile="$WORKSPACE/build-root/install-vpp_debug-native/vpp/bin/vpp"
54 local binfile="$WORKSPACE/build-root/install-vpp-native/vpp/bin/vpp"
57 echo "Generating stack trace from core file: $corefile"
58 STACKTRACE="${corefile}.stacktrace"
59 gdb "$binfile" $corefile -ex 'source -v /tmp/gdb-commands' -ex quit > $STACKTRACE
60 # remove the core to save space
61 echo "Removing core file: $corefile"
63 # Dump stacktrace to console log
64 if [ -f $STACKTRACE ] ; then
65 echo -e "\n=====[ $STACKTRACE ]=====\n$(cat $STACKTRACE)\n=====[ $STACKTRACE ]=====\n"
67 echo "Stacktrace file not generated!"
72 # Delete existing archives dir to ensure current artifact upload
73 rm -rf "$WS_ARCHIVES_DIR"
74 mkdir -p "$WS_ARCHIVES_DIR"
76 # Log the build environment variables
77 echo "Logging build environment variables in '$BUILD_ENV_LOG'..."
80 echo "WS_ARCHIVE_ARTIFACTS = '$WS_ARCHIVE_ARTIFACTS'"
81 if [ -n "${WS_ARCHIVE_ARTIFACTS}" ]; then
83 shopt -s globstar # Enable globstar to copy archives
84 archive_artifacts=$(echo ${WS_ARCHIVE_ARTIFACTS})
85 shopt -u globstar # Disable globstar
86 for file in $archive_artifacts; do
87 if [ -f "$file" ] ; then
88 fname="$(basename $file)"
89 # Decompress core.gz file
90 if grep -qe '^core.*\.gz$' <<<"$fname" ; then
91 echo "Uncompressing core file $file"
95 # Convert core file to stacktrace
96 if [ "${fname::4}" = "core" ] ; then
97 generate_vpp_stacktrace_and_delete_core $file
98 [ -z "$STACKTRACE" ] && continue
101 # Set destination filename
102 if [ "${file::26}" = "/tmp/vpp-failed-unittests/" ] ; then
103 destfile=$WS_ARCHIVES_DIR${file:25}
105 destfile=$WS_ARCHIVE_DIR$file
107 echo "Archiving '$file' to '$destfile'"
108 destdir="$(dirname $destfile)"
112 echo "Not archiving '$file'"
118 # find and gzip any 'text' files
119 find $WS_ARCHIVES_DIR -type f -print0 \
121 | egrep -e ':.*text.*' \
123 | xargs -d'\n' -r gzip
125 echo "Workspace archived artifacts:"
126 ls -alR $WS_ARCHIVES_DIR