Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update build description on build cancellation #862

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
import hudson.model.Queue;
import hudson.model.Result;
import hudson.model.Run;
import hudson.security.ACL;
import hudson.util.RunList;
import jenkins.model.Jenkins;
import org.acegisecurity.context.SecurityContext;
import org.acegisecurity.context.SecurityContextHolder;
import org.jenkinsci.plugins.ghprb.Ghprb;
import org.jenkinsci.plugins.ghprb.GhprbCause;
import org.jenkinsci.plugins.ghprb.extensions.GhprbBuildStep;
Expand Down Expand Up @@ -99,12 +102,18 @@ protected void cancelCurrentBuilds(Job<?, ?> project,
);
run.addAction(this);
run.getExecutor().interrupt(Result.ABORTED);
// Save the current security context before changing it
SecurityContext origContext = SecurityContextHolder.getContext();
// Switch current security context to 'SYSTEM' to have privileges to update build's description
SecurityContextHolder.getContext().setAuthentication(ACL.SYSTEM);
run.setDescription(run.getDescription() + "<br>Cancelled by ghprb plugin due to PR update");
// Reset current security context
SecurityContextHolder.setContext(origContext);
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Error while trying to interrupt build!", e);
}
}
}

}

public void onScheduleBuild(Job<?, ?> project, GhprbCause cause) {
Expand Down
Loading