Skip to content

Fix Jenkins.instance is missing#149

Merged
jakub-bochenski merged 10 commits into
jenkinsci:masterfrom
Seros:fix-global-config
Jan 16, 2026
Merged

Fix Jenkins.instance is missing#149
jakub-bochenski merged 10 commits into
jenkinsci:masterfrom
Seros:fix-global-config

Conversation

@Seros

@Seros Seros commented Jan 9, 2026

Copy link
Copy Markdown

Merges #138, #147 and salemove#1 to fix https://issues.jenkins.io/browse/JENKINS-71693

Testing done

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests that demonstrate the feature works or the issue is fixed

@Seros Seros requested a review from a team as a code owner January 9, 2026 08:59

@jakub-bochenski jakub-bochenski left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

@jakub-bochenski

Copy link
Copy Markdown

Thanks for the PR

@Seros Seros requested a review from jakub-bochenski January 16, 2026 09:39
@Seros

Seros commented Jan 16, 2026

Copy link
Copy Markdown
Author

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

@jakub-bochenski

Copy link
Copy Markdown

@Seros great, thanks!

@jakub-bochenski

Copy link
Copy Markdown

Hmm I see there are some conflicts now, that's a bit strange.

Can you please rebase it on latest master?

@Seros

Seros commented Jan 16, 2026

Copy link
Copy Markdown
Author

I don't see any conflicts and the branch is up-to-date

@jakub-bochenski

Copy link
Copy Markdown

That's weird, GH tells me This branch cannot be rebased due to conflicts

Vladimir Kuznichenkov and others added 10 commits January 16, 2026 14:29
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
@Seros

Seros commented Jan 16, 2026

Copy link
Copy Markdown
Author

Sorry for some reason my git behaved weird. Now the rebase worked

@jakub-bochenski jakub-bochenski merged commit 696c827 into jenkinsci:master Jan 16, 2026
15 checks passed
@jakub-bochenski

Copy link
Copy Markdown

Alright, thanks again.

I think automatic releases should pick this up.

@ANGkeith

Copy link
Copy Markdown

Thanks for fixing this.

How does the automatic release mechanism detect this change?

The most recent release I see is from Aug 31, 2023:
https://github.com/jenkinsci/logstash-plugin/releases

@jakub-bochenski

Copy link
Copy Markdown

Uh, I guess something didn't click. Let me check

@jakub-bochenski

Copy link
Copy Markdown

I've rewritten the commit history, hopefully automatic releases pick it up now :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants