From 9388ce551ecea0ea1e930042ea81b569c03925eb Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Mon, 27 Feb 2017 20:35:17 +0100 Subject: [PATCH] Travis - redirect output of sonar build into file --- .travis/background-job-funcs.sh | 43 +++++++++++++++++++++++++++++++++ .travis/build-push.sh | 2 +- .travis/build-site.sh | 32 +----------------------- .travis/build-sonar.sh | 18 ++++++++++++++ 4 files changed, 63 insertions(+), 32 deletions(-) create mode 100644 .travis/background-job-funcs.sh create mode 100644 .travis/build-sonar.sh diff --git a/.travis/background-job-funcs.sh b/.travis/background-job-funcs.sh new file mode 100644 index 0000000000..5db6740207 --- /dev/null +++ b/.travis/background-job-funcs.sh @@ -0,0 +1,43 @@ +# +# Helper functions to run a chatty, long task in the background, +# redirecting the output to file and keep travis happy by regularly +# writing to the log. +# +# This is to workaround the travis log length limit of 4MB +# Solution from http://stackoverflow.com/questions/26082444/how-to-work-around-travis-cis-4mb-output-limit/26082445#26082445 +# +# Source this file into the shell script, that needs it. +# +# expected variables +# Name | Example Value +# PING_SLEEP | 30s +# BUILD_OUTPUT | /tmp/build-step-logfile.out +# PING_PID_FILE | /tmp/build-step-ping.pid + +touch $BUILD_OUTPUT + +dump_output() { + echo Tailing the last 100 lines of output: + tail -100 $BUILD_OUTPUT +} +kill_ping() { + if [ -e $PING_PID_FILE ]; then + PING_LOOP_PID=$(cat $PING_PID_FILE) + kill $PING_LOOP_PID + rm $PING_PID_FILE + fi +} +error_handler() { + kill_ping + echo ERROR: An error was encountered with the build. + dump_output + exit 1 +} +# If an error occurs, run our error handler to output a tail of the build +trap 'error_handler' ERR + +# Set up a repeating loop to send some output to Travis. +bash -c "while true; do echo \$(date) - building ...; sleep $PING_SLEEP; done" & +PING_LOOP_PID=$! +echo "$PING_LOOP_PID" > $PING_PID_FILE + diff --git a/.travis/build-push.sh b/.travis/build-push.sh index b2ba734ce5..41a4152994 100644 --- a/.travis/build-push.sh +++ b/.travis/build-push.sh @@ -41,6 +41,6 @@ fi if [[ "$VERSION" == *-SNAPSHOT && "$TRAVIS_BRANCH" == "master" ]]; then # only do a clean build for sonar, if we are executing a snapshot build, otherwise we can't reuse the build from above for the release - mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent package sonar:sonar -Dsonar.host.url=https://sonarqube.com -Dsonar.login=${SONAR_TOKEN} -B -V + bash .travis/build-sonar.sh fi diff --git a/.travis/build-site.sh b/.travis/build-site.sh index 0d2ff744d5..af320a06db 100644 --- a/.travis/build-site.sh +++ b/.travis/build-site.sh @@ -1,41 +1,11 @@ #!/bin/bash set -ev -# Do not log the output, to avoid the travis log length limit of 4MB -# Solution from http://stackoverflow.com/questions/26082444/how-to-work-around-travis-cis-4mb-output-limit/26082445#26082445 - - - export PING_SLEEP=30s export BUILD_OUTPUT=/tmp/build-site.out export PING_PID_FILE=/tmp/build-site-ping.pid -touch $BUILD_OUTPUT - -dump_output() { - echo Tailing the last 500 lines of output: - tail -500 $BUILD_OUTPUT -} -kill_ping() { - if [ -e $PING_PID_FILE ]; then - PING_LOOP_PID=$(cat $PING_PID_FILE) - kill $PING_LOOP_PID - rm $PING_PID_FILE - fi -} -error_handler() { - kill_ping - echo ERROR: An error was encountered with the build. - dump_output - exit 1 -} -# If an error occurs, run our error handler to output a tail of the build -trap 'error_handler' ERR - -# Set up a repeating loop to send some output to Travis. -bash -c "while true; do echo \$(date) - building ...; sleep $PING_SLEEP; done" & -PING_LOOP_PID=$! -echo "$PING_LOOP_PID" > $PING_PID_FILE +source .travis/background-job-funcs.sh # Run the build, redirect output into the file mvn site site:stage -Psite -B -V >> $BUILD_OUTPUT 2>&1 diff --git a/.travis/build-sonar.sh b/.travis/build-sonar.sh new file mode 100644 index 0000000000..3a7bcbafa0 --- /dev/null +++ b/.travis/build-sonar.sh @@ -0,0 +1,18 @@ +#!/bin/bash +set -ev + +export PING_SLEEP=30s +export BUILD_OUTPUT=/tmp/build-sonar.out +export PING_PID_FILE=/tmp/build-sonar-ping.pid + +source .travis/background-job-funcs.sh + +# Run the build, redirect output into the file +mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent package sonar:sonar -Dsonar.host.url=https://sonarqube.com -Dsonar.login=${SONAR_TOKEN} -B -V >> $BUILD_OUTPUT 2>&1 + +# The build finished without returning an error so dump a tail of the output +dump_output + +# nicely terminate the ping output loop +kill_ping +