Skip to content

Instantly share code, notes, and snippets.

@ankon
Last active June 6, 2016 10:31
Show Gist options
  • Save ankon/d6a0eb6040eff6f8eb38631bfaa411e3 to your computer and use it in GitHub Desktop.
Save ankon/d6a0eb6040eff6f8eb38631bfaa411e3 to your computer and use it in GitHub Desktop.
Taming Maven Verbosity on Travis
#!/bin/sh
# Filter maven output and inject 'travis_fold'/'travis_time' markers
exec awk '
BEGIN {
attn=0
id=0
start=0
end=0
}
{
if (attn==1 && match($0, /^\[INFO\] Building /)) {
if (id>0) {
if (start>0) {
"date +%s%N"|getline end
close("date +%s%N")
printf "travis_time:end:maven.%d:start=%d,end=%d,duration=%d\n", id, start, end, (end-start)
}
printf "travis_fold:end:maven.%d\n", id
}
id++
printf "travis_fold:start:maven.%d\n", id
"date +%s%N"|getline start
close("date +%s%N")
printf "travis_time:start:maven.%d\n", id
} else if (match($0,/^\[INFO\] -+$/)) {
attn=1
} else {
attn=0
}
print
}
END {
if (id>0) {
if (start>0) {
"date +%s%N"|getline end
close("date +%s%N")
printf "travis_time:end:maven.%d:start=%d,end=%d,duration=%d\n", id, start, end, (end-start)
}
printf "travis_fold:end:maven.%d\n", id
}
}'
@ankon
Copy link
Author

ankon commented Jun 6, 2016

Using this as a filter will kill the maven exit status, so use it like this when you need the status:

((((MAVEN_OPTS="-Xmx256m" mvn clean install; echo $? >&3) |filter-maven-travis.sh maven >&4) 3>&1) | (read xs; exit $xs)) 4>&1

See also: http://stackoverflow.com/a/16530815/196315

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment