jenkinsci / build-timeout-plugin

Jenkins build-timeout plugin
https://plugins.jenkins.io/build-timeout/
31 stars 80 forks source link

Fix bug introduced in PR #95 #98

Closed krisstern closed 2 years ago

krisstern commented 2 years ago

Fixes #97

Description

Use additional try/catch statements to handle the ClassCastException that arises for projects that do not actually belong to the hudson.model.Project class. The bug was first introduced in PR #95, but was not caught by the tests.

Checklist

gjabouley-invn commented 2 years ago

Hi

sorry to jump in, but just to confirm, seeing below log means the exception is properly caught by your code:

[2022-08-29 09:15:55.030] [WARNING] [hudson.plugins.build_timeout.global.GlobalTimeOutConfiguration timeOutFor] job_with_timeout#98949 cannot allow individual jobs to overwrite timeout due to ClassCastException
java.lang.ClassCastException: class hudson.matrix.MatrixProject cannot be cast to class hudson.model.Project (hudson.matrix.MatrixProject is in unnamed module of loader jenkins.util.AntClassLoader @4722b12d; hudson.model.Project is in unnamed module of loader org.eclipse.jetty.webapp.WebAppClassLoader @36b4fe2a)
        at hudson.plugins.build_timeout.global.GlobalTimeOutConfiguration.timeOutFor(GlobalTimeOutConfiguration.java:91)
        at hudson.plugins.build_timeout.global.GlobalTimeOutRunListener.setUpEnvironment(GlobalTimeOutRunListener.java:43)
        at hudson.model.AbstractBuild$AbstractBuildExecution.createLauncher(AbstractBuild.java:615)
        at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:483)
        at hudson.model.Run.execute(Run.java:1897)
        at hudson.matrix.MatrixBuild.run(MatrixBuild.java:323)
        at hudson.model.ResourceController.execute(ResourceController.java:101)
        at hudson.model.Executor.run(Executor.java:442)

Thanks for your work

krisstern commented 2 years ago

Hi @gjabouley-invn Yup, that is the warning due to the exception properly caught by the new code. It's my pleasure!

gjabouley-invn commented 2 years ago

Ok thanks for the confirmation.

So far, as we are using a lot of Matrix Jobs, this warning and the exception stack is bloating our logs. This is strange that even for jobs not using the build timeout feature, the warning is raised...

krisstern commented 2 years ago

Sure, sounds good

gjabouley-invn commented 2 years ago

Is it normal that even for matrix jobs not using the build timeout feature, the warning is raised ?

krisstern commented 2 years ago

Actually I don't think it is normal, or at least it is not expected