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

Cancel pending triggered build when parent project is cancelled #363

Merged
merged 2 commits into from
Nov 22, 2023

Conversation

hashar
Copy link
Contributor

@hashar hashar commented Nov 21, 2023

Cancel triggered build on InterruptException

When a triggering project is cancelled by interrupting its Executor thread and a triggered project is waiting in the build queue (via waitForStart()) the InterruptedException is not handled. The tiggered project is properly cancelled, but the triggering project is left in the queue and will eventually run when a slot is available.

Catch InterruptException while waiting for the triggered project to start and cancel the queued run.

Stacktrace with parameterized-trigger-2.44:

org.jenkinsci.plugins.postbuildscript.PostBuildScriptException: java.lang.InterruptedException
    at org.jenkinsci.plugins.postbuildscript.processor.Processor.processBuildSteps(Processor.java:190)
    at org.jenkinsci.plugins.postbuildscript.processor.Processor.processScripts(Processor.java:91)
    at org.jenkinsci.plugins.postbuildscript.processor.Processor.process(Processor.java:79)
    at org.jenkinsci.plugins.postbuildscript.processor.Processor.process(Processor.java:73)
    at org.jenkinsci.plugins.postbuildscript.PostBuildScript.perform(PostBuildScript.java:116)
    at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
    at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:803)
    at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:752)
    at hudson.model.Build$BuildExecution.post2(Build.java:177)
    at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:697)
    at hudson.model.Run.execute(Run.java:1932)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:429)
Caused by: java.lang.InterruptedException
    at java.base/java.lang.Object.wait(Native Method)
    at java.base/java.lang.Object.wait(Object.java:328)
    at hudson.remoting.AsyncFutureImpl.get(AsyncFutureImpl.java:79)
    at hudson.model.queue.FutureImpl.waitForStart(FutureImpl.java:68)
    at hudson.plugins.parameterizedtrigger.TriggerBuilder.perform(TriggerBuilder.java:146)
    at org.jenkinsci.plugins.postbuildscript.processor.Processor.processBuildSteps(Processor.java:180)
    ... 13 more

Reference: https://phabricator.wikimedia.org/T282893

Testing done

I merely wrote a unit test which interrupts the triggering project and assert the triggered downstream project get cancelled.I am most certainly going to deploy the proposed fix to our production.

Submitter checklist

@hashar
Copy link
Contributor Author

hashar commented Nov 21, 2023

I think I managed to build a test covering it things to do tomorrow:

  • rebase on master
  • file the pull request description
  • review the coverage report

@hashar hashar force-pushed the T282893 branch 2 times, most recently from 2fc62fc to c3acb20 Compare November 22, 2023 10:16
When a triggering project is cancelled by interrupting its Executor
thread and a triggered project is waiting in the build queue (via
`waitForStart()`) the InterruptedException is not handled.  The tiggered
project is properly cancelled, but the triggering project is left in the
queue and will eventually run when a slot is available.

Catch InterruptException while waiting for the triggered project to
start and cancel the queued run.

Stacktrace with parameterized-trigger-2.44:

org.jenkinsci.plugins.postbuildscript.PostBuildScriptException: java.lang.InterruptedException
    at org.jenkinsci.plugins.postbuildscript.processor.Processor.processBuildSteps(Processor.java:190)
    at org.jenkinsci.plugins.postbuildscript.processor.Processor.processScripts(Processor.java:91)
    at org.jenkinsci.plugins.postbuildscript.processor.Processor.process(Processor.java:79)
    at org.jenkinsci.plugins.postbuildscript.processor.Processor.process(Processor.java:73)
    at org.jenkinsci.plugins.postbuildscript.PostBuildScript.perform(PostBuildScript.java:116)
    at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
    at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:803)
    at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:752)
    at hudson.model.Build$BuildExecution.post2(Build.java:177)
    at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:697)
    at hudson.model.Run.execute(Run.java:1932)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:429)
Caused by: java.lang.InterruptedException
    at java.base/java.lang.Object.wait(Native Method)
    at java.base/java.lang.Object.wait(Object.java:328)
    at hudson.remoting.AsyncFutureImpl.get(AsyncFutureImpl.java:79)
    at hudson.model.queue.FutureImpl.waitForStart(FutureImpl.java:68)
    at hudson.plugins.parameterizedtrigger.TriggerBuilder.perform(TriggerBuilder.java:146)
    at org.jenkinsci.plugins.postbuildscript.processor.Processor.processBuildSteps(Processor.java:180)
    ... 13 more

https://phabricator.wikimedia.org/T282893
@hashar hashar changed the title Cancel waiting build on InterruptedException Cancel pending triggered build when parent project is cancelled Nov 22, 2023
@hashar hashar marked this pull request as ready for review November 22, 2023 10:35
@hashar hashar requested a review from a team as a code owner November 22, 2023 10:35
Copy link
Contributor

@MarkEWaite MarkEWaite left a comment

Choose a reason for hiding this comment

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

Thanks very much!

MarkEWaite added a commit to MarkEWaite/repository-permissions-updater that referenced this pull request Nov 22, 2023
jenkinsci/parameterized-trigger-plugin#366 is
the pull request to enable continuous delivery in the parameterized
trigger plugin.

I performed the previous release manually and would rather have the
simplification of automated releases since we now have a pending bug
fix pull request and a pending enhancement.

Bug fix:

* jenkinsci/parameterized-trigger-plugin#357

Enhancement:

* jenkinsci/parameterized-trigger-plugin#363

I'm not a user of the plugin, so I want to simplfy my contributions to
the plugin so that they will be released automatically.
@hashar
Copy link
Contributor Author

hashar commented Nov 22, 2023

Thanks very much!

Thanks!! I really appreciate you took a few seconds to thank me about this since I barely know java and that patch took me quite a few hours of sweat to achieve :-]

Copy link
Contributor

@gounthar gounthar left a comment

Choose a reason for hiding this comment

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

Thanks a lot for this contribution. 👍

@gounthar gounthar merged commit b7c8232 into jenkinsci:master Nov 22, 2023
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants