Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DockerBuilderPublisher now throws a better cloud-not-found error. #796

Merged
merged 5 commits into from
Aug 10, 2020

Conversation

pjdarton
Copy link
Member

One of my co-workers foudn their build failed with the following (rather unhelpful) error:

ERROR: Build step failed with exception
java.util.NoSuchElementException
	at com.google.common.collect.AbstractIterator.next(AbstractIterator.java:154)
	at com.google.common.collect.Iterators.find(Iterators.java:722)
	at com.google.common.collect.Iterables.find(Iterables.java:643)
	at com.nirima.jenkins.plugins.docker.utils.JenkinsUtils.getServer(JenkinsUtils.java:100)
	at com.nirima.jenkins.plugins.docker.builder.DockerBuilderPublisher.getCloud(DockerBuilderPublisher.java:234)
	at com.nirima.jenkins.plugins.docker.builder.DockerBuilderPublisher.perform(DockerBuilderPublisher.java:453)
	at hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:78)
	at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
	at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:741)
	at hudson.model.Build$BuildExecution.build(Build.java:206)
	at hudson.model.Build$BuildExecution.doRun(Build.java:163)
	at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
	at hudson.model.Run.execute(Run.java:1856)
	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
	at hudson.model.ResourceController.execute(ResourceController.java:97)
	at hudson.model.Executor.run(Executor.java:428)
Build step 'Build / Publish Docker Image' marked build as failure

This PR is intended to improve that error so that the solution is more self-evident.

Refactor: Ditch JenkinsUtils.getServers() in favour of DockerCloud.instances()
Refactor: Moved bulk of contents of JenkinsUtils.getServer(String) to DockerCloud.findCloudByName(String) which returns null on failure.
Refactor: Renamed JenkinsUtils.getServer(String) to getCloudByNameOrThrow(String) to better describe what it does.
Refactor: Added getServerNames() to JenkinsUtils and removed implementation of same from DockerManagement.
Enhancement: JenkinsUtils.getCloudByNameOrThrow(String) now throws a human-friendly exception when it doesn't find a cloud of the given name instead of a nasty exception.
@stefanDeveloper
Copy link

I run into the same problem. Are there any recommendations how to fix it?

@pjdarton
Copy link
Member Author

pjdarton commented Aug 3, 2020

You'll find a build of this PR here and you can download the .hpi file & install it into your Jenkins server (using the "Advanced" tab on the plugins page) if you don't want to wait for an official release.

Note that this doesn't get rid of the error, it just makes the error report more helpful so that folks who encounter this error are informed of what they did wrong. If you're hitting this error, the actual fix is to ensure that your build does not ask for a cloud that doesn't exist 😉

@pjdarton pjdarton added the enhancement A PR providing an enhancement to existing functionality. label Aug 3, 2020
@pjdarton pjdarton merged commit cd41bf9 into jenkinsci:master Aug 10, 2020
@pjdarton pjdarton deleted the better_error_for_cloudnotfound branch August 10, 2020 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A PR providing an enhancement to existing functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants