Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-50116

Last changes history becomes empty after Jenkins restart

    Details

    • Similar Issues:

      Description

      After a restart the Last changes history becomes empty. This is explained by following comment on JENKINS-49368:

      https://github.com/jenkinsci/last-changes-plugin/commit/0cb6083a31b207099c5400e4f4a93bee8510f3a5 will not work correctly after the Jenkins restart. The class has no readResolve() resolution, so the value will be null when you save new jobs and reload them from the disk. It will cause NPEs in methods like getLastChangesBuilds().

       

      getLastChangesBuilds() is what we use to create the history page.

      Note that after a job run the history is restored.

        Attachments

          Activity

          Hide
          rmpestano Rafael Pestano added a comment - - edited

          Hi Oleg Nenashev,

          For fixing JENKINS-49368 we had to make the job instance variable transient and now users are facing an NPE as you predicted.

          You've suggested:

          I would actually suggest modifying getJob() to restore the field if null and then switch all the code to using this method instead of the direct field access. Your mileage may vary

          Can you point me to an example on how I could achieve that? I've read https://wiki.jenkins.io/display/JENKINS/Hint+on+retaining+backward+compatibility but could not figure it out on how I would change getJob() in order to restore it.

          Thanks in advance!

          Show
          rmpestano Rafael Pestano added a comment - - edited Hi Oleg Nenashev , For fixing JENKINS-49368 we had to make the job instance variable transient and now users are facing an NPE as you predicted. You've suggested: I would actually suggest modifying getJob() to restore the field if null and then switch all the code to using this method instead of the direct field access. Your mileage may vary Can you point me to an example on how I could achieve that? I've read https://wiki.jenkins.io/display/JENKINS/Hint+on+retaining+backward+compatibility but could not figure it out on how I would change getJob() in order to restore it. Thanks in advance!
          Hide
          danielbeck Daniel Beck added a comment -

          The project action looks like it should be created in a https://javadoc.jenkins.io/jenkins/model/TransientActionFactory.html for the appropriate job type (AbstractProject) rather than stored with the job.

          It could be attached to any project, and getIcon overloaded to only show when one of the newest N builds has an Action attached. This would be more efficient than always traversing all builds.

          Show
          danielbeck Daniel Beck added a comment - The project action looks like it should be created in a https://javadoc.jenkins.io/jenkins/model/TransientActionFactory.html for the appropriate job type (AbstractProject) rather than stored with the job. It could be attached to any project, and getIcon overloaded to only show when one of the newest N builds has an Action attached. This would be more efficient than always traversing all builds.
          Hide
          rmpestano Rafael Pestano added a comment -

          Hi Daniel Beck, thank you very much for the hint. Do you have any docs or sample project using TransientActionFactory?

           

          As an example I've found github plugin link action and they use the concept of job property, see here. Do I need it?  When/how the action is stored on the factory? 

           

           

          Show
          rmpestano Rafael Pestano added a comment - Hi Daniel Beck , thank you very much for the hint. Do you have any docs or sample project using TransientActionFactory?   As an example I've found github plugin link action and they use the concept of job property, see here . Do I need it?  When/how the action is stored on the factory?     
          Hide
          danielbeck Daniel Beck added a comment -

          There's no need to store the project-level action. It can be transient, hence the name.

          https://jenkins.io/doc/developer/extensions/jenkins-core/#transientactionfactory might help.

          Show
          danielbeck Daniel Beck added a comment - There's no need to store the project-level action. It can be transient, hence the name. https://jenkins.io/doc/developer/extensions/jenkins-core/#transientactionfactory might help.
          Hide
          rmpestano Rafael Pestano added a comment -

          Hi again Daniel Beck,

           

          I got some progress here and now it is working (I can get LastChanges history after jenkins restart) but I still need to traverse all builds (now on the transient factory)  so I think it can be improved, see changes here.

          Also when I add the transient factory I get duplicated last changes icon on the left panel (see attached image) .

           

           

          Show
          rmpestano Rafael Pestano added a comment - Hi again Daniel Beck ,   I got some progress here and now it is working (I can get LastChanges history after jenkins restart) but I still need to traverse all builds (now on the transient factory)  so I think it can be improved, see changes here . Also when I add the transient factory I get duplicated last changes icon on the left panel (see attached image) .    
          Hide
          danielbeck Daniel Beck added a comment -

          Make the transient action factory the only source for project actions – not any job property or whatever else you did.

          Show
          danielbeck Daniel Beck added a comment - Make the transient action factory the only source for project actions – not any job property or whatever else you did.
          Hide
          rmpestano Rafael Pestano added a comment -

          Fixed for v2.6.3

          Show
          rmpestano Rafael Pestano added a comment - Fixed for v2.6.3

            People

            • Assignee:
              rmpestano Rafael Pestano
              Reporter:
              rmpestano Rafael Pestano
            • Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: