Fox
Fox

Reputation: 417

Jenkins execute action after delete build

I need to execute some action after build has been deleted (by user or automatically) on Jenkins.

Actually, I need the following:

  1. Send http-request with info about deleted build.
  2. Delete build artifacts on remote location.

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

Answers (2)

ayushindin
ayushindin

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

Triangle
Triangle

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

Related Questions