3 set +e # Do not affect the build result if some part of archiving fails.
5 # Print out git status at the end of the build before we archive if $WORKSPACE
7 if [ -d "$WORKSPACE/.git" ]; then
9 echo "----------> Git Status Report"
14 echo "----------> Archiving build to logs server"
15 # Configure wget to not print download status when we download logs or when
16 # Jenkins is installing Maven (To be clear this is the Jenkins Maven plugin
17 # using a shell script itself that we are unable to modify directly to affect
19 echo "verbose=off" > ~/.wgetrc
21 ARCHIVES_DIR="$JENKINS_HOSTNAME/$JOB_NAME/$BUILD_NUMBER"
22 [ "$LOGS_SERVER" ] || LOGS_SERVER="https://logs.onap.org"
23 [ "$LOGS_REPO_URL" ] || LOGS_REPO_URL="https://nexus.onap.org/service/local/repositories/logs"
25 echo "Build logs: <a href=\"$LOGS_SERVER/$SILO/$ARCHIVES_DIR\">$LOGS_SERVER/$SILO/$ARCHIVES_DIR</a>"
28 cd .archives/ || exit 1
30 cat > deploy-archives.xml <<EOF
31 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
32 <modelVersion>4.0.0</modelVersion>
33 <groupId>logs</groupId>
34 <artifactId>logs</artifactId>
35 <version>1.0.0</version>
36 <packaging>pom</packaging>
41 <groupId>org.apache.maven.plugins</groupId>
42 <artifactId>maven-deploy-plugin</artifactId>
43 <version>2.8.2</version>
49 <groupId>org.sonatype.plugins</groupId>
50 <artifactId>maven-upload-plugin</artifactId>
51 <version>0.0.1</version>
57 <goal>upload-file</goal>
60 <serverId>onap-log-archives</serverId>
61 <repositoryUrl>$LOGS_REPO_URL/content-compressed</repositoryUrl>
62 <file>archives.zip</file>
63 <repositoryPath>$SILO</repositoryPath>
73 mkdir -p "$ARCHIVES_DIR"
74 mkdir -p "$WORKSPACE/archives"
75 if [ ! -z "$ARCHIVE_ARTIFACTS" ]; then
77 shopt -s globstar # Enable globstar to copy archives
78 for f in $ARCHIVE_ARTIFACTS; do
79 [[ -e $f ]] || continue # handle the case of no files to archive
80 echo "Archiving $f" >> "$WORKSPACE/.archives/$ARCHIVES_DIR/_archives.log"
82 mkdir -p "$WORKSPACE/archives/$dir"
83 mv "$f" "$WORKSPACE/archives/$f"
85 shopt -u globstar # Disable globstar once archives are copied
90 # Ignore logging if archives doesn't exist
91 mv "$WORKSPACE/archives/" "$ARCHIVES_DIR" > /dev/null 2>&1
92 touch "$ARCHIVES_DIR/_build-details.txt"
93 echo "build-url: ${BUILD_URL}" >> "$ARCHIVES_DIR/_build-details.txt"
94 env | grep -v PASSWORD > "$ARCHIVES_DIR/_build-enviroment-variables.txt"
97 touch "$ARCHIVES_DIR/_sys-info.txt"
99 echo -e "uname -a:\n $(uname -a) \n"
100 echo -e "df -h:\n $(df -h) \n"
101 echo -e "free -m:\n $(free -m) \n"
102 echo -e "nproc:\n $(nproc) \n"
103 echo -e "lscpu:\n $(lscpu) \n"
104 echo -e "ip addr:\n $(/sbin/ip addr) \n"
105 } 2>&1 | tee -a "$ARCHIVES_DIR/_sys-info.txt"
107 # Magic string used to trim console logs at the appropriate level during wget
108 echo "-----END_OF_BUILD-----"
109 wget -O "$ARCHIVES_DIR/console.log" "${BUILD_URL}consoleText"
110 wget -O "$ARCHIVES_DIR/console-timestamp.log" "$BUILD_URL/timestamps?time=HH:mm:ss&appendLog"
111 sed -i '/^-----END_OF_BUILD-----$/,$d' "$ARCHIVES_DIR/console.log"
112 sed -i '/^.*-----END_OF_BUILD-----$/,$d' "$ARCHIVES_DIR/console-timestamp.log"
114 gzip "$ARCHIVES_DIR"/*.txt "$ARCHIVES_DIR"/*.log
115 # find and gzip any 'text' files
116 find "$ARCHIVES_DIR" -type f -print0 \
118 | egrep -e ':.*text.*' \
120 | xargs -d'\n' -r gzip
121 # Compress Java heap dumps using xz
122 find "$ARCHIVES_DIR" -type f -name \*.hprof -print0 | xargs -0 xz
124 zip -r archives.zip "$JENKINS_HOSTNAME/" >> "$ARCHIVES_DIR/_archives.log"