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

Invalid <null/> element added to <triggers/> in job causing NPE on job load

      On several occasions recently, while editing my matrix jobs, I've noticed that Jenkins has lost the SCM configuration for git polling and replaced it with an invalid entry in the job xml:

      <triggers>
        <null/>
      </triggers>
      

      that causes the job to fail to load when Jenkins is restarted, with:

      Failed Loading job bdr_linux
      java.lang.NullPointerException
      	at hudson.model.AbstractProject.onLoad(AbstractProject.java:326)
      	at hudson.matrix.MatrixProject.onLoad(MatrixProject.java:496)
      	at hudson.model.Items.load(Items.java:279)
      	at jenkins.model.Jenkins$18.run(Jenkins.java:2599)
      	at org.jvnet.hudson.reactor.TaskGraphBuilder$TaskImpl.run(TaskGraphBuilder.java:169)
      	at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:282)
      	at jenkins.model.Jenkins$7.runTask(Jenkins.java:885)
      	at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:210)
      	at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:117)
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      	at java.lang.Thread.run(Thread.java:701)
      

      I haven't yet nailed down a way to reproduce this, but it seems to occur most often around when I've also been having issues with configuration elements throwing exceptions on save.

      The job appears to just "vanish" from the job list, as Jenkins doesn't show broken jobs in the UI at all. To find out what happened I had to go digging in the config XML.

      I version my configuration XML, so I was able to see the following in the most recent diff for jobs/bdr_linux/config.xml:

         <triggers>
      -    <hudson.triggers.SCMTrigger>
      -      <spec>H/5 * * * *</spec>
      -      <ignorePostCommitHooks>false</ignorePostCommitHooks>
      -    </hudson.triggers.SCMTrigger>
      +    <null/>
         </triggers>
      

      To repair the job, I can revert that hunk, or just delete the invalid null element then re-create the trigger in the UI.

      So there are a couple of problems here:

      • A null element like that is invalid and should never be written out, as it cannot be consumed; and
      • the trigger configuration is being lost.

          [JENKINS-23914] Invalid <null/> element added to <triggers/> in job causing NPE on job load

          Craig Ringer added a comment -

          Looking at the git history for the job, I see that whenever this happened the git configuration for the job was also lost, e.g.

          -  <scm class="hudson.plugins.git.GitSCM" plugin="git@2.2.2">
          -    <configVersion>2</configVersion>
          -    ....
          -  </scm>
          +  <scm class="hudson.scm.NullSCM"/>
          

          Craig Ringer added a comment - Looking at the git history for the job, I see that whenever this happened the git configuration for the job was also lost, e.g. - <scm class= "hudson.plugins.git.GitSCM" plugin= "git@2.2.2" > - <configVersion>2</configVersion> - .... - </scm> + <scm class= "hudson.scm.NullSCM" />

          Craig Ringer added a comment -

          I wonder if this is related to the way the matrix plugin sets NullSCM for all child projects?

          Craig Ringer added a comment - I wonder if this is related to the way the matrix plugin sets NullSCM for all child projects?

          Daniel Beck added a comment -

          How are you editing these jobs? Via the UI?

          Daniel Beck added a comment - How are you editing these jobs? Via the UI?

          Craig Ringer added a comment -

          Daniel, I've only edited them via the web UI, with the exception of repairing the <null/> breakage the two times it's occurred.

          The job I've observed the issue with gets edited quite frequently. I've only noticed this problem a couple of times. Until recently I've always been in a rush when working on it so unfortunately I didn't note all the details.

          I'll attach the current config.xml . The version attached, the latest working version, has the build-timeout plugin enabled, but I only just installed that so it can be ignored for this purpose. Similarly, the s3-plugin in the config.xml is version s3@0.7-SNAPSHOT (because I've fixed a couple of bugs since 0.6), but I've seen the issue with 0.6 too.

          The config.xml is unedited. There's nothing secret in there, it's for an open source project anyway.

          I'll also attach the config.xml from the most recent time I noticed it break.

          Craig Ringer added a comment - Daniel, I've only edited them via the web UI, with the exception of repairing the <null/> breakage the two times it's occurred. The job I've observed the issue with gets edited quite frequently. I've only noticed this problem a couple of times. Until recently I've always been in a rush when working on it so unfortunately I didn't note all the details. I'll attach the current config.xml . The version attached, the latest working version, has the build-timeout plugin enabled, but I only just installed that so it can be ignored for this purpose. Similarly, the s3-plugin in the config.xml is version s3@0.7-SNAPSHOT (because I've fixed a couple of bugs since 0.6), but I've seen the issue with 0.6 too. The config.xml is unedited. There's nothing secret in there, it's for an open source project anyway. I'll also attach the config.xml from the most recent time I noticed it break.

          Craig Ringer added a comment -

          bdr_linux_config.xml: config file for current working build. See prior comment for details.

          bdr_linux_broken_config.xml: config file last time I noticed it break.

          Craig Ringer added a comment - bdr_linux_config.xml: config file for current working build. See prior comment for details. bdr_linux_broken_config.xml: config file last time I noticed it break.

          Craig Ringer added a comment -

          I know this is frustratingly vague, by the way. I've cranked the log levels up and will be watching for it happening again. I'm pretty sure it's occurred as a result of exceptions being thrown during configuration save, but beyond that can't be too sure.

          Craig Ringer added a comment - I know this is frustratingly vague, by the way. I've cranked the log levels up and will be watching for it happening again. I'm pretty sure it's occurred as a result of exceptions being thrown during configuration save, but beyond that can't be too sure.

          Still an issue with 1.598.
          Beside Trigger and GitSCM, <logRotator> and <EnvInjectJobProperty>}} are also deleted. And <jdk> is set to default.

          Pushing a backup with jenkins_cli update-job is working fine.

          After restoring a working version I tried making the same changes as before but I couldn't reproduce the bug anymore.

          Martin Heinzerling added a comment - Still an issue with 1.598. Beside Trigger and GitSCM, <logRotator> and <EnvInjectJobProperty>}} are also deleted. And <jdk> is set to default. Pushing a backup with jenkins_cli update-job is working fine. After restoring a working version I tried making the same changes as before but I couldn't reproduce the bug anymore.

          Mike Christof added a comment - - edited

          This is still happening with Jenkins ver. 1.609

          Edit: The job that happened was a "Build Flow" and not a matrix job. Not sure if its relevant though.

          Mike Christof added a comment - - edited This is still happening with Jenkins ver. 1.609 Edit: The job that happened was a "Build Flow" and not a matrix job. Not sure if its relevant though.

          Daniel Beck added a comment -

          Audit Trail plugin and/or Job Config History (best use both) may allow you to determine who changed the job config in what way, when.

          Daniel Beck added a comment - Audit Trail plugin and/or Job Config History (best use both) may allow you to determine who changed the job config in what way, when.

          I had the same issue with Jenkins 2.19.4, and I used Job Config History plugin to restore the previous trigger config.
          Currently I cannot use Poll SCM option because it writes the null element and prevents any change on the job config!

            <triggers>
              <null/>
              <hudson.triggers.SCMTrigger>
                <spec>H/10 * * * *</spec>
                <ignorePostCommitHooks>false</ignorePostCommitHooks>
              </hudson.triggers.SCMTrigger>
            </triggers>
          

          Sergio Fernandes added a comment - I had the same issue with Jenkins 2.19.4, and I used Job Config History plugin to restore the previous trigger config. Currently I cannot use Poll SCM option because it writes the null element and prevents any change on the job config! <triggers> <null/> <hudson.triggers.SCMTrigger> <spec> H/10 * * * * </spec> <ignorePostCommitHooks> false </ignorePostCommitHooks> </hudson.triggers.SCMTrigger> </triggers>

            Unassigned Unassigned
            ringerc Craig Ringer
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: