blob: 4d0945aa677ba1782cefd6ce0f1b17615f695b18 [file] [log] [blame]
Andrew Grimbergebc710a2017-01-30 12:59:38 -08001#!/bin/bash
2
3set +e # Do not affect the build result if some part of archiving fails.
4
Andrew Grimbergd831bb42017-04-06 10:31:52 -07005# Print out git status at the end of the build before we archive if $WORKSPACE
6# is a git repo.
7if [ -d "$WORKSPACE/.git" ]; then
8 echo ""
9 echo "----------> Git Status Report"
10 git status
11fi
12
13echo ""
14echo "----------> 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
18# wget).
19echo "verbose=off" > ~/.wgetrc
20
Andrew Grimbergebc710a2017-01-30 12:59:38 -080021ARCHIVES_DIR="$JENKINS_HOSTNAME/$JOB_NAME/$BUILD_NUMBER"
Andrew Grimbergd831bb42017-04-06 10:31:52 -070022[ "$LOGS_SERVER" ] || LOGS_SERVER="https://logs.onap.org"
23[ "$LOGS_REPO_URL" ] || LOGS_REPO_URL="https://nexus.onap.org/service/local/repositories/logs"
Andrew Grimbergebc710a2017-01-30 12:59:38 -080024
25echo "Build logs: <a href=\"$LOGS_SERVER/$SILO/$ARCHIVES_DIR\">$LOGS_SERVER/$SILO/$ARCHIVES_DIR</a>"
26
27mkdir .archives
Andrew Grimbergd831bb42017-04-06 10:31:52 -070028cd .archives/ || exit 1
Andrew Grimbergebc710a2017-01-30 12:59:38 -080029
30cat > 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>
37
38 <build>
39 <plugins>
40 <plugin>
41 <groupId>org.apache.maven.plugins</groupId>
42 <artifactId>maven-deploy-plugin</artifactId>
43 <version>2.8.2</version>
44 <configuration>
45 <skip>true</skip>
46 </configuration>
47 </plugin>
48 <plugin>
49 <groupId>org.sonatype.plugins</groupId>
50 <artifactId>maven-upload-plugin</artifactId>
51 <version>0.0.1</version>
52 <executions>
53 <execution>
54 <id>publish-site</id>
55 <phase>deploy</phase>
56 <goals>
57 <goal>upload-file</goal>
58 </goals>
59 <configuration>
Andrew Grimbergd831bb42017-04-06 10:31:52 -070060 <serverId>onap-log-archives</serverId>
Andrew Grimbergebc710a2017-01-30 12:59:38 -080061 <repositoryUrl>$LOGS_REPO_URL/content-compressed</repositoryUrl>
62 <file>archives.zip</file>
63 <repositoryPath>$SILO</repositoryPath>
64 </configuration>
65 </execution>
66 </executions>
67 </plugin>
68 </plugins>
69 </build>
70</project>
71EOF
72
Andrew Grimbergd831bb42017-04-06 10:31:52 -070073mkdir -p "$ARCHIVES_DIR"
74mkdir -p "$WORKSPACE/archives"
75if [ ! -z "$ARCHIVE_ARTIFACTS" ]; then
76 pushd "$WORKSPACE"
Andrew Grimbergebc710a2017-01-30 12:59:38 -080077 shopt -s globstar # Enable globstar to copy archives
Andrew Grimbergd831bb42017-04-06 10:31:52 -070078 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"
81 dir=$(dirname "$f")
82 mkdir -p "$WORKSPACE/archives/$dir"
83 mv "$f" "$WORKSPACE/archives/$f"
Andrew Grimbergebc710a2017-01-30 12:59:38 -080084 done
85 shopt -u globstar # Disable globstar once archives are copied
86 popd
87fi
88
89
90# Ignore logging if archives doesn't exist
Andrew Grimbergd831bb42017-04-06 10:31:52 -070091mv "$WORKSPACE/archives/" "$ARCHIVES_DIR" > /dev/null 2>&1
92touch "$ARCHIVES_DIR/_build-details.txt"
93echo "build-url: ${BUILD_URL}" >> "$ARCHIVES_DIR/_build-details.txt"
94env | grep -v PASSWORD > "$ARCHIVES_DIR/_build-enviroment-variables.txt"
Andrew Grimbergebc710a2017-01-30 12:59:38 -080095
96# capture system info
Andrew Grimbergd831bb42017-04-06 10:31:52 -070097touch "$ARCHIVES_DIR/_sys-info.txt"
98{
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"
Andrew Grimbergebc710a2017-01-30 12:59:38 -0800106
107# Magic string used to trim console logs at the appropriate level during wget
108echo "-----END_OF_BUILD-----"
Andrew Grimbergd831bb42017-04-06 10:31:52 -0700109wget -O "$ARCHIVES_DIR/console.log" "${BUILD_URL}consoleText"
110wget -O "$ARCHIVES_DIR/console-timestamp.log" "$BUILD_URL/timestamps?time=HH:mm:ss&appendLog"
111sed -i '/^-----END_OF_BUILD-----$/,$d' "$ARCHIVES_DIR/console.log"
112sed -i '/^.*-----END_OF_BUILD-----$/,$d' "$ARCHIVES_DIR/console-timestamp.log"
Andrew Grimbergebc710a2017-01-30 12:59:38 -0800113
Andrew Grimbergd831bb42017-04-06 10:31:52 -0700114gzip "$ARCHIVES_DIR"/*.txt "$ARCHIVES_DIR"/*.log
Andrew Grimbergebc710a2017-01-30 12:59:38 -0800115# find and gzip any 'text' files
Andrew Grimbergd831bb42017-04-06 10:31:52 -0700116find "$ARCHIVES_DIR" -type f -print0 \
Andrew Grimbergebc710a2017-01-30 12:59:38 -0800117 | xargs -0r file \
118 | egrep -e ':.*text.*' \
119 | cut -d: -f1 \
120 | xargs -d'\n' -r gzip
Andrew Grimbergd831bb42017-04-06 10:31:52 -0700121# Compress Java heap dumps using xz
122find "$ARCHIVES_DIR" -type f -name \*.hprof -print0 | xargs -0 xz
Andrew Grimbergebc710a2017-01-30 12:59:38 -0800123
Andrew Grimbergd831bb42017-04-06 10:31:52 -0700124zip -r archives.zip "$JENKINS_HOSTNAME/" >> "$ARCHIVES_DIR/_archives.log"
Andrew Grimbergebc710a2017-01-30 12:59:38 -0800125du -sh archives.zip