Skip to content

Commit

Permalink
[FIXED JENKINS-23342] Check, if docker URL was provided
Browse files Browse the repository at this point in the history
  • Loading branch information
vjuranek committed Jun 5, 2014
1 parent 9a45992 commit dbf6b27
Showing 1 changed file with 19 additions and 4 deletions.
Expand Up @@ -50,10 +50,16 @@ public DockerCommand getDockerCmd() {
@Override
public boolean perform(@SuppressWarnings("rawtypes") AbstractBuild build, Launcher launcher, BuildListener listener)
throws AbortException {

ConsoleLogger clog = new ConsoleLogger(listener);

if (getDescriptor().getDockerClient() == null) {
clog.logError("docker client is not initialized, command '" + dockerCmd.getDescriptor().getDisplayName()
+ "' was aborted. Check Jenkins server log which Docker client wasn't initialized");
throw new AbortException("Docker client wasn't initialized.");
}

try {

dockerCmd.execute(build, clog);
} catch (DockerException e) {
clog.logError("command '" + dockerCmd.getDescriptor().getDisplayName() + "' failed: " + e.getMessage());
Expand All @@ -77,9 +83,15 @@ public static final class DescriptorImpl extends BuildStepDescriptor<Builder> {

public DescriptorImpl() {
load();

if (dockerUrl == null || dockerUrl.isEmpty()) {
LOGGER.warning("Docker URL is not set, docker client won't be initialized");
return;
}

try {
dockerClient = new DockerClient(dockerUrl);
} catch(DockerException e) {
} catch (DockerException e) {
LOGGER.warning("Cannot create Docker client: " + e.getCause());
}
}
Expand All @@ -100,10 +112,13 @@ public String getDisplayName() {
@Override
public boolean configure(StaplerRequest req, JSONObject formData) throws FormException {
dockerUrl = formData.getString("dockerUrl");
if (dockerUrl == null || dockerUrl.isEmpty())
throw new FormException("Docker REST URL cannot be empty", "dockerUrl");

save();
try {
dockerClient = new DockerClient(dockerUrl);
} catch(DockerException e) {
} catch (DockerException e) {
LOGGER.warning("Cannot create Docker client: " + e.getCause());
}
return super.configure(req, formData);
Expand Down

0 comments on commit dbf6b27

Please sign in to comment.