Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-24156] Add option for Docker client version
  • Loading branch information
vjuranek committed Aug 11, 2014
1 parent b83a946 commit 09046d6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
Expand Up @@ -26,6 +26,7 @@
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;

import com.github.dockerjava.client.Config.DockerClientConfigBuilder;
import com.github.dockerjava.client.DockerClient;
import com.github.dockerjava.client.DockerException;

Expand Down Expand Up @@ -80,6 +81,7 @@ public DescriptorImpl getDescriptor() {
public static final class DescriptorImpl extends BuildStepDescriptor<Builder> {

private String dockerUrl;
private String dockerVersion;
private transient DockerClient dockerClient;

public DescriptorImpl() {
Expand All @@ -91,16 +93,18 @@ public DescriptorImpl() {
}

try {
dockerClient = new DockerClient(dockerUrl);
DockerClientConfigBuilder dcb = new DockerClientConfigBuilder().withUri(dockerUrl).withVersion(dockerVersion);
dockerClient = new DockerClient(dcb.build());
} catch (DockerException e) {
LOGGER.warning("Cannot create Docker client: " + e.getCause());
}
}

public FormValidation doTestConnection(@QueryParameter String dockerUrl) throws IOException, ServletException {
LOGGER.fine("Trying to get client for " + dockerUrl);
public FormValidation doTestConnection(@QueryParameter String dockerUrl, @QueryParameter String dockerVersion) throws IOException, ServletException {
LOGGER.fine(String.format("Trying to get client for %s and version", dockerUrl, dockerVersion));
try {
dockerClient = new DockerClient(dockerUrl);
DockerClientConfigBuilder dcb = new DockerClientConfigBuilder().withUri(dockerUrl).withVersion(dockerVersion);
dockerClient = new DockerClient(dcb.build());
if(dockerClient.execute(dockerClient.pingCmd()) != 200) {
return FormValidation.error("Cannot ping REST endpoint of " + dockerUrl);
}
Expand All @@ -123,6 +127,7 @@ public String getDisplayName() {
@Override
public boolean configure(StaplerRequest req, JSONObject formData) throws FormException {
dockerUrl = formData.getString("dockerUrl");
dockerVersion = formData.getString("dockerVersion");
if (dockerUrl == null || dockerUrl.isEmpty()) {
LOGGER.severe("Docker URL is empty, Docker build test plugin cannot work without Docker URL being set up properly");
//JENKINS-23733 doen't block user to save the config if admin decides so
Expand All @@ -131,7 +136,8 @@ public boolean configure(StaplerRequest req, JSONObject formData) throws FormExc

save();
try {
dockerClient = new DockerClient(dockerUrl);
DockerClientConfigBuilder dcb = new DockerClientConfigBuilder().withUri(dockerUrl).withVersion(dockerVersion);
dockerClient = new DockerClient(dcb.build());
} catch (DockerException e) {
LOGGER.warning("Cannot create Docker client: " + e.getCause());
}
Expand All @@ -141,6 +147,10 @@ public boolean configure(StaplerRequest req, JSONObject formData) throws FormExc
public String getDockerUrl() {
return dockerUrl;
}

public String getDockerVersion() {
return dockerVersion;
}

public DockerClient getDockerClient() {
return dockerClient;
Expand Down
Expand Up @@ -4,6 +4,13 @@
<f:entry title="Docker URL" field="dockerUrl" description="Docker server REST API URL">
<f:textbox />
</f:entry>

<f:advanced align="left">
<f:entry field="dockerVersion" title="Docker version">
<f:textbox />
</f:entry>
</f:advanced>

<f:validateButton title="${%Test Connection}" progress="${%Testing...}" method="testConnection" with="dockerUrl" />
</f:section>

Expand Down

0 comments on commit 09046d6

Please sign in to comment.