blob: bfe0bcbc707d6647bbd26ca5372f1b5df145b00c [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
5ARCHIVES_DIR="$JENKINS_HOSTNAME/$JOB_NAME/$BUILD_NUMBER"
6[ "$LOGS_SERVER" ] || LOGS_SERVER="https://logs.open-o.org"
7[ "$LOGS_REPO_URL" ] || LOGS_REPO_URL="https://nexus.open-o.org/service/local/repositories/logs"
8
9echo "Build logs: <a href=\"$LOGS_SERVER/$SILO/$ARCHIVES_DIR\">$LOGS_SERVER/$SILO/$ARCHIVES_DIR</a>"
10
11mkdir .archives
12cd .archives/
13
14cat > deploy-archives.xml <<EOF
15<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">
16 <modelVersion>4.0.0</modelVersion>
17 <groupId>logs</groupId>
18 <artifactId>logs</artifactId>
19 <version>1.0.0</version>
20 <packaging>pom</packaging>
21
22 <build>
23 <plugins>
24 <plugin>
25 <groupId>org.apache.maven.plugins</groupId>
26 <artifactId>maven-deploy-plugin</artifactId>
27 <version>2.8.2</version>
28 <configuration>
29 <skip>true</skip>
30 </configuration>
31 </plugin>
32 <plugin>
33 <groupId>org.sonatype.plugins</groupId>
34 <artifactId>maven-upload-plugin</artifactId>
35 <version>0.0.1</version>
36 <executions>
37 <execution>
38 <id>publish-site</id>
39 <phase>deploy</phase>
40 <goals>
41 <goal>upload-file</goal>
42 </goals>
43 <configuration>
44 <serverId>open-o-log-archives</serverId>
45 <repositoryUrl>$LOGS_REPO_URL/content-compressed</repositoryUrl>
46 <file>archives.zip</file>
47 <repositoryPath>$SILO</repositoryPath>
48 </configuration>
49 </execution>
50 </executions>
51 </plugin>
52 </plugins>
53 </build>
54</project>
55EOF
56
57mkdir -p $ARCHIVES_DIR
58mkdir -p $WORKSPACE/archives
59if [ ! -z "${{ARCHIVE_ARTIFACTS}}" ]; then
60 pushd $WORKSPACE
61 shopt -s globstar # Enable globstar to copy archives
62 archive_artifacts=$(echo ${{ARCHIVE_ARTIFACTS}})
63 for f in $archive_artifacts; do
64 echo "Archiving $f"
65 mkdir -p $WORKSPACE/archives/$(dirname $f)
66 mv $f $WORKSPACE/archives/$f
67 done
68 shopt -u globstar # Disable globstar once archives are copied
69 popd
70fi
71
72
73# Ignore logging if archives doesn't exist
74mv $WORKSPACE/archives/ $ARCHIVES_DIR > /dev/null 2>&1
75touch $ARCHIVES_DIR/_build-details.txt
76echo "build-url: ${{BUILD_URL}}" >> $ARCHIVES_DIR/_build-details.txt
77env > $ARCHIVES_DIR/_build-enviroment-variables.txt
78
79# capture system info
80touch $ARCHIVES_DIR/_sys-info.txt
81{{
82 echo -e "uname -a:\n `uname -a` \n"
83 echo -e "df -h:\n `df -h` \n"
84 echo -e "free -m:\n `free -m` \n"
85 echo -e "nproc:\n `nproc` \n"
86 echo -e "lscpu:\n `lscpu` \n"
87 echo -e "ip addr:\n `/sbin/ip addr` \n"
88}} 2>&1 | tee -a $ARCHIVES_DIR/_sys-info.txt
89
90# Magic string used to trim console logs at the appropriate level during wget
91echo "-----END_OF_BUILD-----"
92wget -O $ARCHIVES_DIR/console.log ${{BUILD_URL}}consoleText
93wget -O $ARCHIVES_DIR/console-timestamp.log ${{BUILD_URL}}/timestamps?time=HH:mm:ss\&appendLog
94sed -i '/^-----END_OF_BUILD-----$/,$d' $ARCHIVES_DIR/console.log
95sed -i '/^.*-----END_OF_BUILD-----$/,$d' $ARCHIVES_DIR/console-timestamp.log
96
97gzip $ARCHIVES_DIR/*.txt $ARCHIVES_DIR/*.log
98# find and gzip any 'text' files
99find $ARCHIVES_DIR -type f -print0 \
100 | xargs -0r file \
101 | egrep -e ':.*text.*' \
102 | cut -d: -f1 \
103 | xargs -d'\n' -r gzip
104
105zip -r archives.zip $JENKINS_HOSTNAME/
106du -sh archives.zip