History Build Killer Issue with build configs of regular type

I am writing a plugin that uses a listener that is triggered at the start of each build. It then looks for previous PR builds that are still running and from the same branch, checks if the previous build is running, and if it is kills it. 

 

public KillBuildTC(@NotNull EventDispatcher<BuildServerListener> events) {

events.addListener(new BuildServerAdapter() {
@Override
public void buildStarted(@NotNull SRunningBuild build) {

BuildPromotion promotion = build.getBuildPromotion();
BuildPromotion previous = promotion.getPreviousBuildPromotion(SelectPrevBuildPolicy.SINCE_LAST_COMPLETE_BUILD);

if(previous == null){ //if no builds set before stop the listener
Loggers.SERVER.info("No previous builds.");
return;
}

final SUser killbilld = build.getOwner();
SBuild prevBuild = previous.getAssociatedBuild();
if(prevBuild instanceof SRunningBuild){
Loggers.SERVER.info("PREVIOUS BUILD RUNNING");
SRunningBuild runningPrev = (SRunningBuild) prevBuild;
runningPrev.stop(killbilld,"History Build (redundant build) stopped");
} else {
Loggers.SERVER.info("PREVIOUS BUILD NOT RUNNING");
return;
}
}
});
}


This works great for build configs that are part of a composite build chain but when it gets to build configs that are type regular it does not work. 

1) a build is ran using the current most up to date branch in github after a commit is made 

2) after making a change to the previously mentioned branch and committing the changes a second build is ran

this makes the first build that is still running obsolete so my plugin kills the first build. This should be where it ends but 

3) a History Build is then created and ran it is triggered by Restarted;Git and has no changes in it. 

 

I don't know how to fix this so there isn't a restart; git trigger. Any Ideas? 

3 comments
Comment actions Permalink

Hi,

SRunningBuild::stop methods re-adds stopped build to the queue in case when the first parameter (user) is null (it works so to handle the cases when build is crashed, but not cancelled by a user) 

As a workaround, you may try to stop builds using Super User (UserModel::getSuperUser)

0
Comment actions Permalink

Thanks for the response!

could you explain what a super user is for me? 

 

0

Please sign in to leave a comment.