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

Default Run Parameter on First Triggered Job Causes NullPointerException

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • core
    • None
    • nothing special

      Setup:
      Jenkins 1.530
      Job1 triggers Job2 on completion
      Job2 requires a run parameter of project "Job1"

      Bug (root cause):
      When an upstream job triggers a downstream job with a run parameter (last successful) of the upstream job, the default does not work correctly. Since the trigger happens before the upstream job is technically complete, the last successful job is actually the one before. Annoying, but easy to work around by manually adding the run parameter to the upstream job or using curl to determine the latest build and using an appropriate delay.

      Consequence of bug:
      When all the old builds are discarded due to aggressive log rotation rules (or not running the build for a while), there is a timing condition that will produce this stack trace:

      Started by upstream project "FullBuild" build number 356
      originally caused by:
      Started by upstream project "IncrementalBuild" build number 422
      originally caused by:
      Started by an SCM change
      Building remotely on jenkins1 in workspace /home/jenkins/workspace/Devtest
      No emails were triggered.
      FATAL: null
      java.lang.NullPointerException
      at hudson.model.RunParameterValue.buildEnvVars(RunParameterValue.java:74)
      at hudson.model.ParametersAction.buildEnvVars(ParametersAction.java:83)
      at hudson.model.AbstractBuild.getEnvironment(AbstractBuild.java:923)
      at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:84)
      at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:60)
      at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
      at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:782)
      at hudson.model.Build$BuildExecution.build(Build.java:199)
      at hudson.model.Build$BuildExecution.doRun(Build.java:160)
      at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:567)
      at hudson.model.Run.execute(Run.java:1603)
      at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
      at hudson.model.ResourceController.execute(ResourceController.java:88)
      at hudson.model.Executor.run(Executor.java:246)

          [JENKINS-20857] Default Run Parameter on First Triggered Job Causes NullPointerException

          Duane Bronson added a comment -

          Finally got the exception reproduced in a more simple configuration. config.xml files attached shortly...

          When there is no crash, you will notice that the UNSET_RUNPARAM is always wrong and sometimes even unset. RUNPARAM, however, is set correct, but doesn't have the extra sub-settings that go along with it like UNSET_RUNPARAM_RESULT or UNSET_RUNPARAM.number=20.

          To reproduce the exception, the two jobs - ParamTest1 and ParamTest2 need to be run a dozen times or so each day. The first run of the day has a chance of triggering this bug (the "consequence" as described above). It took me about 5 days to reproduce it (although usually I only ran about 3 jobs in a day, not a dozen). Entire output is:

          Started by upstream project "ParamTest1" build number 20
          originally caused by:
          Started by user Duane Bronson
          Building remotely on cascade-jenkins1 in workspace /home/jenkins/workspace/ParamTest2
          FATAL: null
          java.lang.NullPointerException
          at hudson.model.RunParameterValue.buildEnvVars(RunParameterValue.java:74)
          at hudson.model.ParametersAction.buildEnvVars(ParametersAction.java:83)
          at hudson.model.AbstractBuild.getEnvironment(AbstractBuild.java:923)
          at hudson.scm.SubversionSCM.checkout(SubversionSCM.java:776)
          at hudson.model.AbstractProject.checkout(AbstractProject.java:1408)
          at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:657)
          at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:88)
          at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:562)
          at hudson.model.Run.execute(Run.java:1603)
          at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
          at hudson.model.ResourceController.execute(ResourceController.java:88)
          at hudson.model.Executor.run(Executor.java:246)

          Duane Bronson added a comment - Finally got the exception reproduced in a more simple configuration. config.xml files attached shortly... When there is no crash, you will notice that the UNSET_RUNPARAM is always wrong and sometimes even unset. RUNPARAM, however, is set correct, but doesn't have the extra sub-settings that go along with it like UNSET_RUNPARAM_RESULT or UNSET_RUNPARAM.number=20. To reproduce the exception, the two jobs - ParamTest1 and ParamTest2 need to be run a dozen times or so each day. The first run of the day has a chance of triggering this bug (the "consequence" as described above). It took me about 5 days to reproduce it (although usually I only ran about 3 jobs in a day, not a dozen). Entire output is: Started by upstream project "ParamTest1" build number 20 originally caused by: Started by user Duane Bronson Building remotely on cascade-jenkins1 in workspace /home/jenkins/workspace/ParamTest2 FATAL: null java.lang.NullPointerException at hudson.model.RunParameterValue.buildEnvVars(RunParameterValue.java:74) at hudson.model.ParametersAction.buildEnvVars(ParametersAction.java:83) at hudson.model.AbstractBuild.getEnvironment(AbstractBuild.java:923) at hudson.scm.SubversionSCM.checkout(SubversionSCM.java:776) at hudson.model.AbstractProject.checkout(AbstractProject.java:1408) at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:657) at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:88) at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:562) at hudson.model.Run.execute(Run.java:1603) at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46) at hudson.model.ResourceController.execute(ResourceController.java:88) at hudson.model.Executor.run(Executor.java:246)

          Duane Bronson added a comment -

          ~jenkins/jobs/ParamTest1/config.xml

          Duane Bronson added a comment - ~jenkins/jobs/ParamTest1/config.xml

          Duane Bronson added a comment -

          ~jenkins/jobs/ParamTest2/config.xml

          Duane Bronson added a comment - ~jenkins/jobs/ParamTest2/config.xml

          Root cause of lastSuccessful build not defaulting to the correct build when triggered by that upstream build seems to be due to PeepholePermalink cache being updated too late.

          Geoff Cummings added a comment - Root cause of lastSuccessful build not defaulting to the correct build when triggered by that upstream build seems to be due to PeepholePermalink cache being updated too late.

          Another scenario which causes the NullPointerException:

          If the build selected in a RunParameter is deleted, you can no longer load any Environment variables from the parameterized build using groovy script, even non RunParameter environment variables.

          A call to build.getEnvironment() will result in a call to RunParameterValue.buildEnvVars()
          As the build selected for the RunParameter has been deleted, it will cause a null pointer when trying to access details from the Run.

          Geoff Cummings added a comment - Another scenario which causes the NullPointerException: If the build selected in a RunParameter is deleted, you can no longer load any Environment variables from the parameterized build using groovy script, even non RunParameter environment variables. A call to build.getEnvironment() will result in a call to RunParameterValue.buildEnvVars() As the build selected for the RunParameter has been deleted, it will cause a null pointer when trying to access details from the Run.

          Code changed in jenkins
          User: gcummings
          Path:
          core/src/main/java/hudson/model/RunParameterValue.java
          http://jenkins-ci.org/commit/jenkins/f22ecf7d9735de332efa831d45350c879e246c08
          Log:
          JENKINS-20857 - Add some null checks to RunParameterValue

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: gcummings Path: core/src/main/java/hudson/model/RunParameterValue.java http://jenkins-ci.org/commit/jenkins/f22ecf7d9735de332efa831d45350c879e246c08 Log: JENKINS-20857 - Add some null checks to RunParameterValue

          Code changed in jenkins
          User: gcummings
          Path:
          test/src/test/java/hudson/model/RunParameterDefinitionTest.java
          http://jenkins-ci.org/commit/jenkins/10ea9941ae2449b5f4c38a30fa5459bc1b62afbb
          Log:
          JENKINS-20857 - add unit test which recreates NullPointerException if selected build has been deleted

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: gcummings Path: test/src/test/java/hudson/model/RunParameterDefinitionTest.java http://jenkins-ci.org/commit/jenkins/10ea9941ae2449b5f4c38a30fa5459bc1b62afbb Log: JENKINS-20857 - add unit test which recreates NullPointerException if selected build has been deleted

          Code changed in jenkins
          User: Kohsuke Kawaguchi
          Path:
          changelog.html
          core/src/main/java/hudson/model/RunParameterValue.java
          test/src/test/java/hudson/model/RunParameterDefinitionTest.java
          http://jenkins-ci.org/commit/jenkins/bdfbf25129f26a729076095088c749ef2ed254e0
          Log:
          [FIXED JENKINS-20857] Merged pull request 1060

          Compare: https://github.com/jenkinsci/jenkins/compare/f1c70147acc9...bdfbf25129f2

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Kohsuke Kawaguchi Path: changelog.html core/src/main/java/hudson/model/RunParameterValue.java test/src/test/java/hudson/model/RunParameterDefinitionTest.java http://jenkins-ci.org/commit/jenkins/bdfbf25129f26a729076095088c749ef2ed254e0 Log: [FIXED JENKINS-20857] Merged pull request 1060 Compare: https://github.com/jenkinsci/jenkins/compare/f1c70147acc9...bdfbf25129f2

          dogfood added a comment -

          Integrated in jenkins_main_trunk #3324
          JENKINS-20857 - Add some null checks to RunParameterValue (Revision f22ecf7d9735de332efa831d45350c879e246c08)
          JENKINS-20857 - add unit test which recreates NullPointerException if selected build has been deleted (Revision 10ea9941ae2449b5f4c38a30fa5459bc1b62afbb)

          Result = SUCCESS
          kohsuke : f22ecf7d9735de332efa831d45350c879e246c08
          Files :

          • core/src/main/java/hudson/model/RunParameterValue.java

          kohsuke : 10ea9941ae2449b5f4c38a30fa5459bc1b62afbb
          Files :

          • test/src/test/java/hudson/model/RunParameterDefinitionTest.java

          dogfood added a comment - Integrated in jenkins_main_trunk #3324 JENKINS-20857 - Add some null checks to RunParameterValue (Revision f22ecf7d9735de332efa831d45350c879e246c08) JENKINS-20857 - add unit test which recreates NullPointerException if selected build has been deleted (Revision 10ea9941ae2449b5f4c38a30fa5459bc1b62afbb) Result = SUCCESS kohsuke : f22ecf7d9735de332efa831d45350c879e246c08 Files : core/src/main/java/hudson/model/RunParameterValue.java kohsuke : 10ea9941ae2449b5f4c38a30fa5459bc1b62afbb Files : test/src/test/java/hudson/model/RunParameterDefinitionTest.java

            Unassigned Unassigned
            nerdmachine Duane Bronson
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: