Andrew Grimberg | ebc710a | 2017-01-30 12:59:38 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | set +e # Do not affect the build result if some part of archiving fails. |
| 4 | |
| 5 | ARCHIVES_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 | |
| 9 | echo "Build logs: <a href=\"$LOGS_SERVER/$SILO/$ARCHIVES_DIR\">$LOGS_SERVER/$SILO/$ARCHIVES_DIR</a>" |
| 10 | |
| 11 | mkdir .archives |
| 12 | cd .archives/ |
| 13 | |
| 14 | cat > 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> |
| 55 | EOF |
| 56 | |
| 57 | mkdir -p $ARCHIVES_DIR |
| 58 | mkdir -p $WORKSPACE/archives |
| 59 | if [ ! -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 |
| 70 | fi |
| 71 | |
| 72 | |
| 73 | # Ignore logging if archives doesn't exist |
| 74 | mv $WORKSPACE/archives/ $ARCHIVES_DIR > /dev/null 2>&1 |
| 75 | touch $ARCHIVES_DIR/_build-details.txt |
| 76 | echo "build-url: ${{BUILD_URL}}" >> $ARCHIVES_DIR/_build-details.txt |
| 77 | env > $ARCHIVES_DIR/_build-enviroment-variables.txt |
| 78 | |
| 79 | # capture system info |
| 80 | touch $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 |
| 91 | echo "-----END_OF_BUILD-----" |
| 92 | wget -O $ARCHIVES_DIR/console.log ${{BUILD_URL}}consoleText |
| 93 | wget -O $ARCHIVES_DIR/console-timestamp.log ${{BUILD_URL}}/timestamps?time=HH:mm:ss\&appendLog |
| 94 | sed -i '/^-----END_OF_BUILD-----$/,$d' $ARCHIVES_DIR/console.log |
| 95 | sed -i '/^.*-----END_OF_BUILD-----$/,$d' $ARCHIVES_DIR/console-timestamp.log |
| 96 | |
| 97 | gzip $ARCHIVES_DIR/*.txt $ARCHIVES_DIR/*.log |
| 98 | # find and gzip any 'text' files |
| 99 | find $ARCHIVES_DIR -type f -print0 \ |
| 100 | | xargs -0r file \ |
| 101 | | egrep -e ':.*text.*' \ |
| 102 | | cut -d: -f1 \ |
| 103 | | xargs -d'\n' -r gzip |
| 104 | |
| 105 | zip -r archives.zip $JENKINS_HOSTNAME/ |
| 106 | du -sh archives.zip |