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

Jenkins.instance is missing. Read the documentation of Jenkins.getInstanceOrNull to see what you are doing wron

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • logstash-plugin
    • None
    • Jenkins 2.415
      Logstash Plugin 2.4.0

      I see this

      java.lang.IllegalStateException: Jenkins.instance is missing. Read the documentation of Jenkins.getInstanceOrNull to see what you are doing wrong.
      	at jenkins.model.Jenkins.get(Jenkins.java:816)
      	at jenkins.model.GlobalConfiguration.all(GlobalConfiguration.java:75)
      	at jenkins.plugins.logstash.LogstashConfiguration.getInstance(LogstashConfiguration.java:289)
      	at jenkins.plugins.logstash.LogstashWriter.getIndexerDao(LogstashWriter.java:162)
      	at jenkins.plugins.logstash.LogstashWriter.getDaoOrNull(LogstashWriter.java:201)
      	at jenkins.plugins.logstash.LogstashWriter.<init>(LogstashWriter.java:82)
      	at jenkins.plugins.logstash.pipeline.GlobalDecorator.decorate(GlobalDecorator.java:41)
      	at org.jenkinsci.plugins.workflow.log.TaskListenerDecorator.decorateAll(TaskListenerDecorator.java:231)
      	at org.jenkinsci.plugins.workflow.log.TaskListenerDecorator$DecoratedTaskListener.getLogger(TaskListenerDecorator.java:269)
      	at org.jenkinsci.plugins.workflow.log.TaskListenerDecorator$CloseableTaskListener.getLogger(TaskListenerDecorator.java:306)
      	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$2.execute(CliGitAPIImpl.java:807)
      	at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$GitCommandMasterToSlaveCallable.call(RemoteGitImpl.java:170)
      	at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$GitCommandMasterToSlaveCallable.call(RemoteGitImpl.java:161)
      	at hudson.remoting.UserRequest.perform(UserRequest.java:211)
      	at hudson.remoting.UserRequest.perform(UserRequest.java:54)
      	at hudson.remoting.Request$2.run(Request.java:377)
      	at hudson.remoting.InterceptingExecutorService.lambda$wrap$0(InterceptingExecutorService.java:78)
      	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
      	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
      	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
      	at java.base/java.lang.Thread.run(Thread.java:833) 

      on the Slave in the log.

          [JENKINS-71693] Jenkins.instance is missing. Read the documentation of Jenkins.getInstanceOrNull to see what you are doing wron

          Marcin added a comment -

          We are noticing the same exception in logs. Global decorator enabled in Manage Jenkins / System

           

          Jenkins 2.401.2

          Logstash Version 2.5.0205.vd05825ed46bd

          Marcin added a comment - We are noticing the same exception in logs. Global decorator enabled in Manage Jenkins / System   Jenkins 2.401.2 Logstash Version 2.5.0205.vd05825ed46bd

          Thomas added a comment - - edited

          Having the same issue when plugin is enabled globally.

          Is there any solution on how to remove the specific error from the console out, until a fix has been released.

          Jenkins 2.414.2

          logstash 2.5.0218.v0a_ff8fefc12b_

          Thomas added a comment - - edited Having the same issue when plugin is enabled globally. Is there any solution on how to remove the specific error from the console out, until a fix has been released. Jenkins 2.414.2 logstash 2.5.0218.v0a_ff8fefc12b_

          Same issue, Jenkins 2.414.3, both logstash 2.5.0218.v0a_ff8fefc12b and 2.5.0205.vd05825ed46bd cause the problem.  It also appears if you use the logstash wrapper for specific pipeline steps. I've noticed that this problem only occurs in pipeline jobs, not freestyle, and only for certain pipeline stages like ones which use git or ansiblePlaybook steps.  Also, it does not seem to occur if you run the same pipeline on the Jenkins master, only on agents (SSH or JNLP).

          Josiah Sansone added a comment - Same issue, Jenkins 2.414.3, both logstash 2.5.0218.v0a_ff8fefc12b and 2.5.0205.vd05825ed46bd cause the problem.  It also appears if you use the logstash wrapper for specific pipeline steps. I've noticed that this problem only occurs in pipeline jobs, not freestyle, and only for certain pipeline stages like ones which use git or ansiblePlaybook steps.  Also, it does not seem to occur if you run the same pipeline on the Jenkins master, only on agents (SSH or JNLP).

          What the status of this issue?

          Izek Greenfield added a comment - What the status of this issue?

          Shreyas added a comment - - edited

          mwinter69 

           

          This issue seems to have been introduced in this commit https://github.com/jenkinsci/logstash-plugin/commit/322d92f560e9245bc1dc434da44c1ccf57c19c6b

          In Logstashwriter.java, getInstance() was changed to get() on line 174 and  ElasticSearch.java on line 243. getInstance has a null check built in. https://javadoc.jenkins-ci.org/jenkins/model/Jenkins.html#getInstanceOrNull()

           

          I think this change was made to include Jenkins agent, as seen from the PR description. 

          • implement TaskListenerDecorator To be able to log globally for pipeline a TaskListenerDecorator must be implemented. Portentially the decorator will be transferred to the agent jvm so everything must be Serializable (this is not tested). * include stage and agent name of stage and/or name of agent are included in the output if the logstash step is inside a stage and/or agent.

          As per the Jenkins doc for getInstanceorNull, "If you must do a runtime check whether you are in the controller or agent, use JenkinsJVM rather than this method, as merely loading the Jenkins class file into an agent JVM can cause linkage errors under some conditions."

          I think this might be the fix.

          Shreyas added a comment - - edited mwinter69     This issue seems to have been introduced in this commit https://github.com/jenkinsci/logstash-plugin/commit/322d92f560e9245bc1dc434da44c1ccf57c19c6b In Logstashwriter.java, getInstance() was changed to get() on line 174 and  ElasticSearch.java on line 243. getInstance has a null check built in. https://javadoc.jenkins-ci.org/jenkins/model/Jenkins.html#getInstanceOrNull( )   I think this change was made to include Jenkins agent, as seen from the PR description.  implement TaskListenerDecorator To be able to log globally for pipeline a TaskListenerDecorator must be implemented. Portentially the decorator will be transferred to the agent jvm so everything must be Serializable (this is not tested) . * include stage and agent name of stage and/or name of agent are included in the output if the logstash step is inside a stage and/or agent. As per the Jenkins doc for getInstanceorNull, "If you must do a runtime check whether you are in the controller or agent, use JenkinsJVM  rather than this method, as merely loading the  Jenkins class file into an agent JVM can cause linkage errors under some conditions." I think this might be the fix.

          Is there any update on this one? having the same issue.

          Richard Dalton added a comment - Is there any update on this one? having the same issue.

          There is a PR with possible fix https://github.com/jenkinsci/logstash-plugin/pull/138#issuecomment-2284235463
          But the PR causes an error message to appear in the logs. Things seem to be working despite this.

          If you are interested in this fix please use the incremental releases to try out this change

          Jakub Bochenski added a comment - There is a PR with possible fix https://github.com/jenkinsci/logstash-plugin/pull/138#issuecomment-2284235463 But the PR causes an error message to appear in the logs. Things seem to be working despite this. If you are interested in this fix please use the incremental releases to try out this change

            jbochenski Jakub Bochenski
            oicfar Rafal Kedziorski
            Votes:
            7 Vote for this issue
            Watchers:
            13 Start watching this issue

              Created:
              Updated: