Reputation: 417
I need to execute some action after build has been deleted (by user or automatically) on Jenkins.
Actually, I need the following:
About #2: I use Artifact Deployer plugin to deploy build, but because of issue https://issues.jenkins-ci.org/browse/JENKINS-26109 build is not deleting on remote location after build has been deleted.
Any way, how I can do something on deleting build? Maybe I have to write script or create plugin?
Upvotes: 1
Views: 2107
Reputation: 111
There is a class RunListener which has method onDeleted.
Do something like this:
import hudson.model.Run;
import hudson.model.listeners.RunListener;
import hudson.Extension;
@Extension
public class DeleteListener extends RunListener<Run> {
@Override
public void onDeleted(Run r) {
// your code here
}
}
Moreover, remember that if you delete job - event onDeleted will not be fired.
Upvotes: 3
Reputation: 1507
I don't think Plugin is required for this. You can write a cron job for this which checks the build directory continuously for any changes in the contents.
$JENKINS_HOME/jobs/your_job_here/builds/
If any of the folder is deleted that means a build is deleted manually/automatically. Then you can trigger a mail or perform whatever task you want to do as now you know a build has been deleted.
Upvotes: 1