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 # Output executor runtime attributes [again] in case the job fails prior to
23 # running setup_executor_env.sh
24 long_line="************************************************************************"
25 OS_ID=$(grep '^ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g')
26 OS_VERSION_ID=$(grep '^VERSION_ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g')
29 echo "Executor Runtime Attributes:"
30 echo "OS: $OS_ID-$OS_VERSION_ID"
32 echo "Nomad Hostname: $(grep search /etc/resolv.conf | cut -d' ' -f2 | head -1)"
33 echo "Container ID: $(hostname)"
36 # Generate gdb-command script to output vpp stack traceback from core files.
37 gdb_cmdfile="/tmp/gdb-commands"
38 cat >$gdb_cmdfile <<'__END__'
40 # gdb $BINFILE $CORE -ex 'source -v gdb-commands' -ex quit
55 thread apply all printstack
62 # Returns stacktrace filename in STACKTRACE
63 generate_vpp_stacktrace_and_delete_core() {
65 if grep -qe 'debug' <<< "$WORKSPACE" ; then
66 local binfile="$WORKSPACE/build-root/install-vpp_debug-native/vpp/bin/vpp"
68 local binfile="$WORKSPACE/build-root/install-vpp-native/vpp/bin/vpp"
71 echo "Generating stack trace from core file: $corefile"
72 STACKTRACE="${corefile}.stacktrace"
73 gdb "$binfile" $corefile -ex 'source -v /tmp/gdb-commands' -ex quit > $STACKTRACE
74 # remove the core to save space
75 echo "Removing core file: $corefile"
77 # Dump stacktrace to console log
78 if [ -f $STACKTRACE ] ; then
79 echo -e "\n=====[ $STACKTRACE ]=====\n$(cat $STACKTRACE)\n=====[ $STACKTRACE ]=====\n"
81 echo "Stacktrace file not generated!"
86 # Delete existing archives dir to ensure current artifact upload
87 rm -rf "$WS_ARCHIVES_DIR"
88 mkdir -p "$WS_ARCHIVES_DIR"
90 # Log the build environment variables
91 echo "Logging build environment variables in '$BUILD_ENV_LOG'..."
94 echo "WS_ARCHIVE_ARTIFACTS = '$WS_ARCHIVE_ARTIFACTS'"
95 if [ -n "${WS_ARCHIVE_ARTIFACTS}" ]; then
97 shopt -s globstar # Enable globstar to copy archives
98 archive_artifacts=$(echo ${WS_ARCHIVE_ARTIFACTS})
99 shopt -u globstar # Disable globstar
100 for file in $archive_artifacts; do
101 if [ -f "$file" ] ; then
102 fname="$(basename $file)"
103 # Decompress core.gz file
104 if grep -qe '^core.*\.gz$' <<<"$fname" ; then
105 echo "Uncompressing core file $file"
109 # Convert core file to stacktrace
110 if [ "${fname::4}" = "core" ] ; then
111 generate_vpp_stacktrace_and_delete_core $file
112 [ -z "$STACKTRACE" ] && continue
115 # Set destination filename
116 if [ "${file::26}" = "/tmp/vpp-failed-unittests/" ] ; then
117 destfile=$WS_ARCHIVES_DIR${file:25}
119 destfile=$WS_ARCHIVE_DIR$file
121 echo "Archiving '$file' to '$destfile'"
122 destdir="$(dirname $destfile)"
126 echo "Not archiving '$file'"
132 # find and gzip any 'text' files
133 find $WS_ARCHIVES_DIR -type f -print0 \
135 | egrep -e ':.*text.*' \
137 | xargs -d'\n' -r gzip
139 echo "Workspace archived artifacts:"
140 ls -alR $WS_ARCHIVES_DIR