Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rerun a failed Jenkins build with clean

Tags:

maven

jenkins

Our commit build (Maven) does not use clean. This makes it considerably faster. But occasionally we get things like a moved or deleted Test class, that stays around and executes and often fails.

Is there a way to configure Jenkins in a way that it tries to rerun the build but doing a mvn clean or clean workspace up front?

like image 859
Jens Schauder Avatar asked Oct 06 '22 04:10

Jens Schauder


1 Answers

How about using "Trigger parameterized build on other projects" post-build action?

For "Projects to build", use "$JOB_NAME" which will trigger the job itself
For "Trigger when build is", use "Failed" from the drop down
Then click "Add Parameters" and select "Current Build Parameters
Finally add "Predefined Parameters", set something like "REBUILD=TRUE"

Now you need a build step that executes before SVN checkout
Install this plugin:
https://wiki.jenkins-ci.org/display/JENKINS/pre-scm-buildstep

Now, in the job configuration, under "Build Environment", there will be a checkmark for "Run buildstep before SCM runs". Check that
Then add build step for "Execute shell" or "Execute Windows batch command", depending on your OS. In that build step, run a simple check for variable "REBUILD" being equal to "TRUE", again based on your OS shell choice. And if true, clean up workspace from shell by deleting all content there. You can be more specific and delete only the SVN checkout folder if needed.

like image 68
Slav Avatar answered Oct 10 '22 02:10

Slav