Friday, November 16, 2007

Random build failures with maven

Some builds are seemingly failing at random, the cause is the fact that maven is downloading corrupted jar files during build time. A possible cause for this is network timeout.

What I am planning to do to correct for this is to try rebuilding the portal up to 3 times if the build fails. Below is script code for how to detect build failures and rebuild if necessary.
The key line is: "if test $? -ne 0; then"
This detects a maven build failure.


maven-2.0.7/bin/mvn -e clean install

if test $? -ne 0; then
echo ----------- MAVEN BUILD FAILED, TRYING AGAIN.. ATTEPMT 1 -----------
maven-2.0.7/bin/mvn -e clean install
fi

if test $? -ne 0; then
echo ----------- MAVEN BUILD FAILED, TRYING AGAIN.. ATTEPMT 2 -----------
maven-2.0.7/bin/mvn -e clean install
fi


if test $? -ne 0; then
echo ----------- MAVEN BUILD FAILED, TRYING AGAIN.. ATTEPMT 3 -----------
maven-2.0.7/bin/mvn -e clean install
fi


if test $? -ne 0; then
echo ----------- MAVEN BUILD FAILED, EXITING -----------
exit 0
fi

1 comment:

Rishi Verma said...

Yes I know.. a loop should be used, but it didn't seem to detect a build failure during the second iteration when I tried using a loop. If someone has this working with a loop, do let me know.