Fix Jenkins.instance is missing#149
Conversation
jakub-bochenski
left a comment
There was a problem hiding this comment.
LGTM, except it seems there are some random imports in LogstashConfiguration.java
Can you please remove them?
Also can you please restore the previous state after setting LogstashConfiguration.getInstance().setEnableGlobally(true);
|
Thanks for the PR |
|
We are running the artifact build from this PR in our Jenkins and can I confirm the issue is fixed without any other errors coming up |
|
@Seros great, thanks! |
|
Hmm I see there are some conflicts now, that's a bit strange. Can you please rebase it on latest master? |
|
I don't see any conflicts and the branch is up-to-date |
|
That's weird, GH tells me |
According to the [doc][1] to get an instance of a config we should use `ExtensionList.lookupSingleton(<your GlobalConfiguration subclass>.class)` Added additional test to handle a remote logging from workflow pipeline job. Initially started to check the code because we got exceptions on agents when using Git checkout: ``` 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:230) at org.jenkinsci.plugins.workflow.log.TaskListenerDecorator$DecoratedTaskListener.getOutputStream(TaskListenerDecorator.java:267) at org.jenkinsci.plugins.workflow.log.OutputStreamTaskListener$Default.getLogger(OutputStreamTaskListener.java:116) at org.jenkinsci.plugins.workflow.log.TaskListenerDecorator$CloseableTaskListener.getLogger(TaskListenerDecorator.java:307) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2801) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2762) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2757) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:2051) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:2063) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.revParse(CliGitAPIImpl.java:1115) at hudson.plugins.git.GitAPI.revParse(GitAPI.java:419) ``` [1]: https://javadoc.jenkins-ci.org/jenkins/model/GlobalConfiguration.html
According to the [doc][1] to get an instance of a config we should use `ExtensionList.lookupSingleton(<your GlobalConfiguration subclass>.class)` Added additional test to handle a remote logging from workflow pipeline job. Initially started to check the code because we got exceptions on agents when using Git checkout: ``` 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:230) at org.jenkinsci.plugins.workflow.log.TaskListenerDecorator$DecoratedTaskListener.getOutputStream(TaskListenerDecorator.java:267) at org.jenkinsci.plugins.workflow.log.OutputStreamTaskListener$Default.getLogger(OutputStreamTaskListener.java:116) at org.jenkinsci.plugins.workflow.log.TaskListenerDecorator$CloseableTaskListener.getLogger(TaskListenerDecorator.java:307) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2801) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2762) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2757) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:2051) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:2063) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.revParse(CliGitAPIImpl.java:1115) at hudson.plugins.git.GitAPI.revParse(GitAPI.java:419) ``` `getIndexerDao` should return `null` if configuration isn't yet available. In that case `getDaoOrNull` will return `null` as it is expected. [1]: https://javadoc.jenkins-ci.org/jenkins/model/GlobalConfiguration.html
|
Sorry for some reason my git behaved weird. Now the rebase worked |
|
Alright, thanks again. I think automatic releases should pick this up. |
|
Thanks for fixing this. How does the automatic release mechanism detect this change? The most recent release I see is from Aug 31, 2023: |
|
Uh, I guess something didn't click. Let me check |
|
I've rewritten the commit history, hopefully automatic releases pick it up now :) |
Merges #138, #147 and salemove#1 to fix https://issues.jenkins.io/browse/JENKINS-71693
Testing done
Submitter checklist