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

Add ability to cancel specific jobs with trigger scoped cancellation when building current patchset or other options similar to server scope. #415

Merged
merged 10 commits into from
Dec 2, 2020

Conversation

MattLud
Copy link
Contributor

@MattLud MattLud commented May 27, 2020

This PR will add the ability for specific jobs to have running builds aborted upon seeing a new patchset pushed. The options added mirror the server-level triggers that currently exist but are instead scoped to trigger that have the options enabled. This should not impact existing server cancellation.

@@ -11,4 +11,6 @@
files="InjectedTest.java"/>
<suppress checks=".+"
files="[/\\]generated-sources[/\\]"/>
<suppress checks="FileLength"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@MattLud MattLud Jun 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind refactoring - my plan is to move that parts of that subclass logic to it's own file. Any concerns with that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Went ahead and did this.

Copy link
Member

@rsandell rsandell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't reviewed everything yet.

@@ -794,7 +798,8 @@ public ListBoxModel doFillVerdictCategoryItems() {
public void notifyBuildEnded(GerritTriggeredEvent event) {
if (event instanceof ChangeBasedEvent) {
IGerritHudsonTriggerConfig serverConfig = getServerConfig(event);
if (serverConfig != null && serverConfig.isGerritBuildCurrentPatchesOnly()) {
if ((serverConfig != null && serverConfig.isGerritBuildCurrentPatchesOnly())
|| this.getBuildCancellationPolicy().isEnabled()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You check for null in EventListener so I guess you need to check for it here as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

/**
* @return the abortNewPatchsets
*/
public boolean isAbortNewPatchsets() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a whole bunch of new fields I'd prefer to just have one bean with the setting in. It can be achieved with for example <f:block> or rather <f:optionalBlock>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will try that out again. My last attempt doing that jelly code ended in tears.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still no success. How would I rewrite the Jelly + java code to make this work?

if (serverConfig != null && serverConfig.isGerritBuildCurrentPatchesOnly()) {
if (t.getBuildCancellationPolicy() != null && t.getBuildCancellationPolicy().isEnabled())
{
t.getRunningJobs().cancelTriggeredJob(changeBasedEvent,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be wrong, but it looks strange; since you aren't calling scheduled here I don't think that it is recorded among the running jobs correctly and so can't be cancelled?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll double check - the code to keep it separate from cancelling ALL jobs with the triggered event was a bit more nuanced.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if we don't have a serverwide or trigger policy, it doesn't get added.

If the trigger policy is set, we add it here: https://github.com/jenkinsci/gerrit-trigger-plugin/pull/415/files#diff-23a1e696752ef9408f31a5c9aa77c5d3R2408

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -91,6 +91,8 @@
private SshServer sshd;
private SshdServerMock serverMock;
private GerritServer gerritServer;
private static final int DELAY = 2000;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you had to do this because you got outside of the area for MagicNumber ignore rule?
You could just increase the number on Line 73.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind moving away from that magical number unless you want it there. Either way I can revert and update the checkstyle or remove it entirely.

…policy

Change-Id: I1e654243a9030635062339f3657f71eb1580ee73
Change-Id: I12c65e99c10d8df714e52157fe730fe519e737a1
@MattLud
Copy link
Contributor Author

MattLud commented Jul 6, 2020

I think all that's left on this is the Jelly code rewrite - is the anything else you need fixed?

* Class for maintaining and synchronizing the runningJobs info.
* Association between patches and the jobs that we're running for them.
*/
public class RunningJobs {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You missed to reformat.

@rsandell
Copy link
Member

rsandell commented Sep 25, 2020

Looks good.
Here is an example of how to make the jelly work. It could probably be made a bit cleaner, maybe by using f:optionalProperty and other things, but at least it should work for you to experiment further with.

@MattLud
Copy link
Contributor Author

MattLud commented Oct 8, 2020

Reworking this PR now to fix tests. Should have an update either today or tomorrow.

@rsandell
Copy link
Member

rsandell commented Oct 9, 2020

And I've probably introduced a merge conflict hell for you today, sorry about that :/

@MattLud
Copy link
Contributor Author

MattLud commented Oct 9, 2020

No worries - I'm tracking down a regression with RunningJobs being moved out anyways.

Change-Id: I208713390358c780587fa7c03ecae96ebfa8c197
…plugin into trigger_cancel_current_patchset

Change-Id: I0b201c254f758b88b4bd34448d53ae1338f5a734
@MattLud
Copy link
Contributor Author

MattLud commented Oct 9, 2020

Pushed new change to branch but this PR isn't updated. May need to poke github to see if there is a sync issue.

Change-Id: I93543b86a3fbd7c84bb9adb28d5a1b9d9755a2db
@MattLud
Copy link
Contributor Author

MattLud commented Oct 12, 2020

@rsandell - Ok ready for review. Lemme know if you want me to rebase/squash commits.

@MattLud
Copy link
Contributor Author

MattLud commented Oct 23, 2020

@rsandell - Not sure what happened on that last check - can it be re-run?

@rsandell
Copy link
Member

@MattLud could you change the title to something more descriptive, for the changelog, and add a description please?

@MattLud
Copy link
Contributor Author

MattLud commented Nov 25, 2020

@MattLud could you change the title to something more descriptive, for the changelog, and add a description please?

Will do! Expect it later today - Thanks again for reviewing it!

@MattLud MattLud changed the title Trigger cancel current patchset Added ability to cancel specific jobs with trigger scoped cancellation when building current patchset or other options similar to server scope. Dec 1, 2020
@MattLud MattLud changed the title Added ability to cancel specific jobs with trigger scoped cancellation when building current patchset or other options similar to server scope. Add ability to cancel specific jobs with trigger scoped cancellation when building current patchset or other options similar to server scope. Dec 1, 2020
@rsandell rsandell merged commit f182f42 into jenkinsci:master Dec 2, 2020
@MattLud MattLud deleted the trigger_cancel_current_patchset branch December 3, 2020 05:11
@romanek-adam
Copy link
Contributor

@MattLud could you maybe provide a specific use case this change addresses? I'd like to understand the rationale and potentially improve on our side by taking advantage of it.

@MattLud
Copy link
Contributor Author

MattLud commented Dec 17, 2020

@romanek-adam Previously, you could only set server-wide setting if a build would be aborted if a new patchet set was published.

Since we run multi-tenant jenkins servers with a variety of needs, we needed granularity to control this at the trigger/job level.

@ctudor
Copy link

ctudor commented Jan 6, 2021

Any reason this change removed my fix for only storing events for the specified gerrit server? Running into the same issues I had before with the latest plugin where we keep replaying events that should not be replayed.

9d95d15#diff-d20ef7cffb03100f9595b376cd9f40692a8b0788597e87830df09fa0f3244a63

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants