jenkinsci / build-timeout-plugin

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

Unexpected Log issue for multi-configuration jobs (Matrix jobs) #100

Closed gjabouley-invn closed 1 year ago

gjabouley-invn commented 2 years ago

Jenkins and plugins versions report

Environment ```text Jenkins: 2.346.3 OS: Linux - 4.15.0-191-generic --- Exclusion:0.15 ace-editor:1.1 all-changes:1.5 analysis-model-api:10.16.1 android-emulator:3.1.3 ant:475.vf34069fef73c antisamy-markup-formatter:2.7 anything-goes-formatter:1.0 apache-httpcomponents-client-4-api:4.5.13-138.v4e7d9a_7b_a_e61 audit-trail:3.11 authentication-tokens:1.4 authorize-project:1.4.0 badge:1.9.1 bootstrap4-api:4.6.0-5 bootstrap5-api:5.2.0-3 bouncycastle-api:2.26 branch-api:2.1046.v0ca_37783ecc5 build-timeout:1.23 caffeine-api:2.9.3-65.v6a_47d0f4d1fe categorized-view:1.12 checks-api:1.7.5 cloudbees-folder:6.740.ve4f4ffa_dea_54 cobertura:1.17 code-coverage-api:3.1.0 command-launcher:84.v4a_97f2027398 conditional-buildstep:1.4.2 copyartifact:1.47 cppcheck:1.26 credentials:1139.veb_9579fca_33b_ credentials-binding:523.vd859a_4b_122e6 custom-tools-plugin:0.8 cvs:2.19.1 dashboard-view:2.447.vda_124dd35f11 data-tables-api:1.12.1-3 display-url-api:2.3.6 docker-commons:1.21 docker-workflow:521.v1a_a_dd2073b_2e dtkit-api:3.0.1 durable-task:500.v8927d9fd99d8 echarts-api:5.3.3-1 email-ext:2.91 emma:1.31 envinject:2.875.v9b_9e962da_a_ec envinject-api:1.199.v3ce31253ed13 extended-choice-parameter:346.vd87693c5a_86c extensible-choice-parameter:1.8.0 external-monitor-job:192.ve979ca_8b_3ccd ez-templates:1.3.5 file-operations:1.11 flexible-publish:0.16.1 font-awesome-api:6.1.2-1 forensics-api:1.15.1 git:4.11.5 git-client:3.11.2 git-server:1.11 github:1.34.5 github-api:1.303-400.v35c2d8258028 github-branch-source:1687.v7618247e672d gradle:1.39.4 greenballs:1.15.1 groovy:442.v817e6d937d6c groovy-postbuild:2.5 handlebars:3.0.8 htmlpublisher:1.30 http_request:1.16 ionicons-api:22.v868b_0c347756 jackson2-api:2.13.3-285.vc03c0256d517 jakarta-activation-api:2.0.1-1 jakarta-mail-api:2.0.1-1 javadoc:226.v71211feb_e7e9 javax-activation-api:1.2.0-4 javax-mail-api:1.6.2-7 jaxb:2.3.6-1 jdk-tool:55.v1b_32b_6ca_f9ca jjwt-api:0.11.5-77.v646c772fddb_0 jnr-posix-api:3.1.15-1 jobConfigHistory:1171.v04b_66d78555e jobgenerator:1.22 jquery:1.12.4-1 jquery-detached:1.2.1 jquery3-api:3.6.0-4 jsch:0.1.55.61.va_e9ee26616e7 junit:1119.1121.vc43d0fc45561 ldap:2.12 locale:180.v207501dff9b_a_ lockable-resources:2.16 login-theme:1.1 mail-watcher-plugin:1.17 mailer:435.v79ef3972b_5c7 mapdb-api:1.0.9-28.vf251ce40855d mask-passwords:3.3 matrix-auth:3.1.5 matrix-project:772.v494f19991984 maven-plugin:3.19 mina-sshd-api-common:2.8.0-36.v8e25ce90d4b_1 mina-sshd-api-core:2.8.0-36.v8e25ce90d4b_1 momentjs:1.1.1 monitoring:1.91.0 msbuild:1.30 naginator:1.18.1 nodelabelparameter:1.11.0 okhttp-api:4.9.3-108.v0feda04578cf pam-auth:1.10 parameterized-trigger:2.45 pipeline-build-step:2.18 pipeline-githubnotify-step:49.vf37bf92d2bc8 pipeline-graph-analysis:195.v5812d95a_a_2f9 pipeline-groovy-lib:612.v84da_9c54906d pipeline-input-step:449.v77f0e8b_845c4 pipeline-milestone-step:101.vd572fef9d926 pipeline-model-api:2.2114.v2654ca_721309 pipeline-model-definition:2.2114.v2654ca_721309 pipeline-model-extensions:2.2114.v2654ca_721309 pipeline-rest-api:2.24 pipeline-stage-step:293.v200037eefcd5 pipeline-stage-tags-metadata:2.2114.v2654ca_721309 pipeline-stage-view:2.24 pipeline-utility-steps:2.13.0 plain-credentials:139.ved2b_9cf7587b plot:2.1.11 plugin-usage-plugin:3.0 plugin-util-api:2.17.0 popper-api:1.16.1-3 popper2-api:2.11.6-1 port-allocator:1.8 prism-api:1.28.0-2 publish-over:0.22 repo:1.15.0 resource-disposer:0.19 rich-text-publisher-plugin:1.4 run-condition:1.5 scm-api:621.vda_a_b_055e58f7 script-security:1175.v4b_d517d6db_f0 sectioned-view:1.25 simple-theme-plugin:103.va_161d09c38c7 snakeyaml-api:1.30.2-76.vc104f7ce9870 sonar:2.14 ssh-agent:295.v9ca_a_1c7cc3a_a_ ssh-credentials:295.vced876c18eb_4 ssh-slaves:1.834.v622da_57f702c sshd:3.242.va_db_9da_b_26a_c3 structs:324.va_f5d6774f3a_d subversion:2.16.0 throttle-concurrents:2.8 timestamper:1.18 token-macro:308.v4f2b_ed62b_b_16 translation:1.16 trilead-api:1.67.vc3938a_35172f uno-choice:2.6.3 variant:59.vf075fe829ccb view-job-filters:2.3 warnings-ng:9.19.1 windows-slaves:1.8.1 workflow-aggregator:590.v6a_d052e5a_a_b_5 workflow-api:1192.v2d0deb_19d212 workflow-basic-steps:991.v43d80fea_ff66 workflow-cps:2759.v87459c4eea_ca_ workflow-durable-task-step:1199.v02b_9244f8064 workflow-job:1207.ve6191ff089f8 workflow-multibranch:716.vc692a_e52371b_ workflow-scm-step:400.v6b_89a_1317c9a_ workflow-step-api:639.v6eca_cd8c04a_a_ workflow-support:838.va_3a_087b_4055b ws-cleanup:0.42 xunit:3.1.0 ```

What Operating System are you using (both controller, and any agents involved in the problem)?

Docker

Reproduction steps

  1. In global configuration, Global Build Time Out is disabled
  2. Create a multi configuration build (matrix job)
  3. just do an "echo" step
  4. run the job

Expected Results

No log in Jenkins logs

Actual Results

Jenkins log:

Aug 29, 2022 2:15:31 PM WARNING hudson.plugins.build_timeout.global.GlobalTimeOutConfiguration timeOutFor
testBuildTimeoutLogIssue#1 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 @33fbe7d2; hudson.model.Project is in unnamed module of loader org.eclipse.jetty.webapp.WebAppClassLoader @19553973)
    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)

Anything else?

Seems since recent changes in GlobalTimeOutConfiguration, the plugin will raise a warning for any Matrix Project runs, even when it is not using the build timeout feature, as this type of job inherits from AbstractProject

Not sure how to fix this, probably needs an extra check...

Related to https://github.com/jenkinsci/build-timeout-plugin/issues/97

krisstern commented 2 years ago

This could be due to the way the code was written in PR #95. Let me take another look and see if we could come up with a patch soon. This is definitely a bug. Thanks for reporting it!

gjabouley-invn commented 2 years ago

Changed the title, as the feature (build timeout) is working fine for matrix jobs (at least for our usage), but there is still some unexpected warnings that are bloating jenkins logs

krisstern commented 1 year ago

I am attempting a fix for this bug with PR #104. Am testing and will cut a new release soon after. My apologies for having taken so long.

krisstern commented 1 year ago

@gjabouley-invn A new release with the patch has been published: https://github.com/jenkinsci/build-timeout-plugin/releases/tag/build-timeout-1.25.

If you have tried it and the problem persists, do let us know.

gjabouley-invn commented 1 year ago

Hello, sorry for the late reply, instance was quite busy so i could not restart it until this morning

After upgrading and restarting, i still see the warning message in the logs:

[2022-12-12 08:58:00.675] [WARNING] [hudson.plugins.build_timeout.global.GlobalTimeOutConfiguration timeOutFor] s
job#872 cannot allow indivdual 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.URLClassLoader2 @49ba1 hudson.model.Project is in unnamed module of loader org.eclipse.jetty.webapp.WebAppClassLoader @44828f6b)
        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:1899)
        at hudson.matrix.MatrixBuild.run(MatrixBuild.java:323)
        at hudson.model.ResourceController.execute(ResourceController.java:107)
        at hudson.model.Executor.run(Executor.java:449)

Seems this line is triggering: https://github.com/krisstern/build-timeout-plugin/blob/bug-fix/global-timeout-configuration-logging/src/main/java/hudson/plugins/build_timeout/global/GlobalTimeOutConfiguration.java#L100

Probably the culprit is https://github.com/krisstern/build-timeout-plugin/blob/bug-fix/global-timeout-configuration-logging/src/main/java/hudson/plugins/build_timeout/global/GlobalTimeOutConfiguration.java#L91, but not sure how-to workaround this (MatrixProject is not a child class of Project...)

krisstern commented 1 year ago

Hi @gjabouley-invn for the follow-up!

I have re-opened the issue and will take another look to see how we could fix this for all hudson.matrix.MatrixProjects over the next few days.

krisstern commented 1 year ago

@gjabouley-invn I have just submitted a PR #105 that seems to be able to bypass the Global Timeout feature for all Matrix jobs, more broadly including all jobs that inherit from the hudson.model.AbstractProject class. I have also included a test for this special case, and the test seems to indicate we have achieved the desired effect. I will follow up and merge the PR if and once the CI/CD checks are all passed.

Have a happy new year!

krisstern commented 1 year ago

@gjabouley-invn I have just published a new release of the plugin (https://github.com/jenkinsci/build-timeout-plugin/releases/tag/build-timeout-1.26). Do test it if and when you can to see if this resolves your problem. If not, we will see what else we can do.

conkers87 commented 1 year ago

I upgraded my Jenkins instance last night and I am seeing the same warnings in my logs this morning for every matrix job. I have version 1.26 installed on my system.

I plan to downgrade to my previous version of the plugin today sometime and see if that resolves the issue or not.

It does seem like everything is still working but my logs are chock full of these warnings so its tough to catch anything else.

Jan 04, 2023 6:03:53 AM WARNING hudson.plugins.build_timeout.global.GlobalTimeOutConfiguration timeOutFor NotRealName#22734 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.URLClassLoader2 @38d4a1c1; hudson.model.Project is in unnamed module of loader org.eclipse.jetty.webapp.WebAppClassLoader @659a969b) at hudson.plugins.build_timeout.global.GlobalTimeOutConfiguration.timeOutFor(GlobalTimeOutConfiguration.java:92) at hudson.plugins.build_timeout.global.GlobalTimeOutRunListener.setUpEnvironment(GlobalTimeOutRunListener.java:39) at hudson.model.AbstractBuild$AbstractBuildExecution.createLauncher(AbstractBuild.java:617) at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:485) at hudson.model.Run.execute(Run.java:1900) at hudson.matrix.MatrixBuild.run(MatrixBuild.java:323) at hudson.model.ResourceController.execute(ResourceController.java:107) at hudson.model.Executor.run(Executor.java:449)

krisstern commented 1 year ago

@conkers87 I think I know why there is an issue. I omitted to get rid of the ClassCastException handling code in the now overloaded timeOutFor() method in the GlobalTimeOutConfiguration class. I have just opened #106 to tidy up the codebase. Would appreciate it if you could try it out for us.

conkers87 commented 1 year ago

@conkers87 I think I know why there is an issue. I omitted to get rid of the ClassCastException handling code in the now overloaded timeOutFor() method in the GlobalTimeOutConfiguration class. I have just opened #106 to tidy up the codebase. Would appreciate it if you could try it out for us.

Happy to update and try anything you can provide, I don't have much experience trying to build a plugin on my own.

krisstern commented 1 year ago

Thanks @conkers87! I have just cut a new release. As I have not much experience testing Matrix jobs, would appreciate any help possible.

krisstern commented 1 year ago

I just fixed the broken Matrix build, and got rid of that warning once and for all.

conkers87 commented 1 year ago

So it actually got worse this time as now my matrix jobs don't run at all..

FATAL: class hudson.matrix.MatrixProject cannot be cast to class hudson.model.Project (hudson.matrix.MatrixProject is in unnamed module of loader jenkins.util.URLClassLoader2 @64f0f5e9; hudson.model.Project is in unnamed module of loader org.eclipse.jetty.webapp.WebAppClassLoader @659a969b) 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.URLClassLoader2 @64f0f5e9; hudson.model.Project is in unnamed module of loader org.eclipse.jetty.webapp.WebAppClassLoader @659a969b) at hudson.plugins.build_timeout.global.GlobalTimeOutConfiguration.timeOutFor(GlobalTimeOutConfiguration.java:97) at hudson.plugins.build_timeout.global.GlobalTimeOutRunListener.setUpEnvironment(GlobalTimeOutRunListener.java:41) at hudson.model.AbstractBuild$AbstractBuildExecution.createLauncher(AbstractBuild.java:617) at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:485) at hudson.model.Run.execute(Run.java:1900) at hudson.matrix.MatrixBuild.run(MatrixBuild.java:323) at hudson.model.ResourceController.execute(ResourceController.java:107) at hudson.model.Executor.run(Executor.java:449)

krisstern commented 1 year ago

@conkers87 Thanks! Actually someone reported that Release 1.27 broke the Matrix Build, so I fixed it in Release 1.28. And I have removed the logging which seems redundant given the context.

conkers87 commented 1 year ago

I managed to install 1.28 late last night and haven't had an error or warning since. Thanks for all the help!

krisstern commented 1 year ago

Glad it worked @conkers87!