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 | |
Andrew Grimberg | d831bb4 | 2017-04-06 10:31:52 -0700 | [diff] [blame] | 5 | # Print out git status at the end of the build before we archive if $WORKSPACE |
| 6 | # is a git repo. |
| 7 | if [ -d "$WORKSPACE/.git" ]; then |
| 8 | echo "" |
| 9 | echo "----------> Git Status Report" |
| 10 | git status |
| 11 | fi |
| 12 | |
| 13 | echo "" |
| 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 |
| 18 | # wget). |
| 19 | echo "verbose=off" > ~/.wgetrc |
| 20 | |
Andrew Grimberg | ebc710a | 2017-01-30 12:59:38 -0800 | [diff] [blame] | 21 | ARCHIVES_DIR="$JENKINS_HOSTNAME/$JOB_NAME/$BUILD_NUMBER" |
Andrew Grimberg | d831bb4 | 2017-04-06 10:31:52 -0700 | [diff] [blame] | 22 | [ "$LOGS_SERVER" ] || LOGS_SERVER="https://logs.onap.org" |
| 23 | [ "$LOGS_REPO_URL" ] || LOGS_REPO_URL="https://nexus.onap.org/service/local/repositories/logs" |
Andrew Grimberg | ebc710a | 2017-01-30 12:59:38 -0800 | [diff] [blame] | 24 | |
| 25 | echo "Build logs: <a href=\"$LOGS_SERVER/$SILO/$ARCHIVES_DIR\">$LOGS_SERVER/$SILO/$ARCHIVES_DIR</a>" |
| 26 | |
| 27 | mkdir .archives |
Andrew Grimberg | d831bb4 | 2017-04-06 10:31:52 -0700 | [diff] [blame] | 28 | cd .archives/ || exit 1 |
Andrew Grimberg | ebc710a | 2017-01-30 12:59:38 -0800 | [diff] [blame] | 29 | |
| 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> |
| 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 Grimberg | d831bb4 | 2017-04-06 10:31:52 -0700 | [diff] [blame] | 60 | <serverId>onap-log-archives</serverId> |
Andrew Grimberg | ebc710a | 2017-01-30 12:59:38 -0800 | [diff] [blame] | 61 | <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> |
| 71 | EOF |
| 72 | |
Andrew Grimberg | d831bb4 | 2017-04-06 10:31:52 -0700 | [diff] [blame] | 73 | mkdir -p "$ARCHIVES_DIR" |
| 74 | mkdir -p "$WORKSPACE/archives" |
| 75 | if [ ! -z "$ARCHIVE_ARTIFACTS" ]; then |
| 76 | pushd "$WORKSPACE" |
Andrew Grimberg | ebc710a | 2017-01-30 12:59:38 -0800 | [diff] [blame] | 77 | shopt -s globstar # Enable globstar to copy archives |
Andrew Grimberg | d831bb4 | 2017-04-06 10:31:52 -0700 | [diff] [blame] | 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" |
| 81 | dir=$(dirname "$f") |
| 82 | mkdir -p "$WORKSPACE/archives/$dir" |
| 83 | mv "$f" "$WORKSPACE/archives/$f" |
Andrew Grimberg | ebc710a | 2017-01-30 12:59:38 -0800 | [diff] [blame] | 84 | done |
| 85 | shopt -u globstar # Disable globstar once archives are copied |
| 86 | popd |
| 87 | fi |
| 88 | |
| 89 | |
| 90 | # Ignore logging if archives doesn't exist |
Andrew Grimberg | d831bb4 | 2017-04-06 10:31:52 -0700 | [diff] [blame] | 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" |
Andrew Grimberg | ebc710a | 2017-01-30 12:59:38 -0800 | [diff] [blame] | 95 | |
| 96 | # capture system info |
Andrew Grimberg | d831bb4 | 2017-04-06 10:31:52 -0700 | [diff] [blame] | 97 | touch "$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 Grimberg | ebc710a | 2017-01-30 12:59:38 -0800 | [diff] [blame] | 106 | |
| 107 | # Magic string used to trim console logs at the appropriate level during wget |
| 108 | echo "-----END_OF_BUILD-----" |
Andrew Grimberg | d831bb4 | 2017-04-06 10:31:52 -0700 | [diff] [blame] | 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" |
Andrew Grimberg | ebc710a | 2017-01-30 12:59:38 -0800 | [diff] [blame] | 113 | |
Andrew Grimberg | d831bb4 | 2017-04-06 10:31:52 -0700 | [diff] [blame] | 114 | gzip "$ARCHIVES_DIR"/*.txt "$ARCHIVES_DIR"/*.log |
Andrew Grimberg | ebc710a | 2017-01-30 12:59:38 -0800 | [diff] [blame] | 115 | # find and gzip any 'text' files |
Andrew Grimberg | d831bb4 | 2017-04-06 10:31:52 -0700 | [diff] [blame] | 116 | find "$ARCHIVES_DIR" -type f -print0 \ |
Andrew Grimberg | ebc710a | 2017-01-30 12:59:38 -0800 | [diff] [blame] | 117 | | xargs -0r file \ |
| 118 | | egrep -e ':.*text.*' \ |
| 119 | | cut -d: -f1 \ |
| 120 | | xargs -d'\n' -r gzip |
Andrew Grimberg | d831bb4 | 2017-04-06 10:31:52 -0700 | [diff] [blame] | 121 | # Compress Java heap dumps using xz |
| 122 | find "$ARCHIVES_DIR" -type f -name \*.hprof -print0 | xargs -0 xz |
Andrew Grimberg | ebc710a | 2017-01-30 12:59:38 -0800 | [diff] [blame] | 123 | |
Andrew Grimberg | d831bb4 | 2017-04-06 10:31:52 -0700 | [diff] [blame] | 124 | zip -r archives.zip "$JENKINS_HOSTNAME/" >> "$ARCHIVES_DIR/_archives.log" |
Andrew Grimberg | ebc710a | 2017-01-30 12:59:38 -0800 | [diff] [blame] | 125 | du -sh archives.zip |