Merge "Fix yamllint for ovsdb"
[releng/builder.git] / jjb / include-raw-deploy-archives.sh
1 #!/bin/bash
2
3 set +e  # Do not affect the build result if some part of archiving fails.
4
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
21 ARCHIVES_DIR="$JENKINS_HOSTNAME/$JOB_NAME/$BUILD_NUMBER"
22 [ "$LOGS_SERVER" ] || LOGS_SERVER="https://logs.opendaylight.org"
23 [ "$LOGS_REPO_URL" ] || LOGS_REPO_URL="https://nexus.opendaylight.org/service/local/repositories/logs"
24
25 echo "Build logs: <a href=\"$LOGS_SERVER/$SILO/$ARCHIVES_DIR\">$LOGS_SERVER/$SILO/$ARCHIVES_DIR</a>"
26
27 mkdir .archives
28 cd .archives/
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>
60               <serverId>opendaylight-log-archives</serverId>
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
73 mkdir -p $ARCHIVES_DIR
74 mkdir -p $WORKSPACE/archives
75 if [ ! -z "${{ARCHIVE_ARTIFACTS}}" ]; then
76     pushd $WORKSPACE
77     shopt -s globstar  # Enable globstar to copy archives
78     archive_artifacts=$(echo ${{ARCHIVE_ARTIFACTS}})
79     for f in $archive_artifacts; do
80         echo "Archiving $f"
81         mkdir -p $WORKSPACE/archives/$(dirname $f)
82         mv $f $WORKSPACE/archives/$f
83     done
84     shopt -u globstar  # Disable globstar once archives are copied
85     popd
86 fi
87
88
89 # Ignore logging if archives doesn't exist
90 mv $WORKSPACE/archives/ $ARCHIVES_DIR > /dev/null 2>&1
91 touch $ARCHIVES_DIR/_build-details.txt
92 echo "build-url: ${{BUILD_URL}}" >> $ARCHIVES_DIR/_build-details.txt
93 env | grep -v PASSWORD > $ARCHIVES_DIR/_build-enviroment-variables.txt
94
95 # capture system info
96 touch $ARCHIVES_DIR/_sys-info.txt
97 {{
98     echo -e "uname -a:\n `uname -a` \n"
99     echo -e "df -h:\n `df -h` \n"
100     echo -e "free -m:\n `free -m` \n"
101     echo -e "nproc:\n `nproc` \n"
102     echo -e "lscpu:\n `lscpu` \n"
103     echo -e "ip addr:\n  `/sbin/ip addr` \n"
104 }} 2>&1 | tee -a $ARCHIVES_DIR/_sys-info.txt
105
106 # Magic string used to trim console logs at the appropriate level during wget
107 echo "-----END_OF_BUILD-----"
108 wget -O $ARCHIVES_DIR/console.log ${{BUILD_URL}}consoleText
109 wget -O $ARCHIVES_DIR/console-timestamp.log "${{BUILD_URL}}/timestamps?time=HH:mm:ss&appendLog"
110 sed -i '/^-----END_OF_BUILD-----$/,$d' $ARCHIVES_DIR/console.log
111 sed -i '/^.*-----END_OF_BUILD-----$/,$d' $ARCHIVES_DIR/console-timestamp.log
112
113 gzip $ARCHIVES_DIR/*.txt $ARCHIVES_DIR/*.log
114 # find and gzip any 'text' files
115 find $ARCHIVES_DIR -type f -print0 \
116                 | xargs -0r file \
117                 | egrep -e ':.*text.*' \
118                 | cut -d: -f1 \
119                 | xargs -d'\n' -r gzip
120
121 zip -r archives.zip $JENKINS_HOSTNAME/ > $ARCHIVES_DIR/_archives-zip.log
122 du -sh archives.zip