diff --git a/docs/attachments/docker-plugin-configuration-script.groovy b/docs/attachments/docker-plugin-configuration-script.groovy index 1fcafd4bf..18461613a 100644 --- a/docs/attachments/docker-plugin-configuration-script.groovy +++ b/docs/attachments/docker-plugin-configuration-script.groovy @@ -1,4 +1,6 @@ +import io.jenkins.docker.client.DockerAPI import com.nirima.jenkins.plugins.docker.DockerCloud +import org.jenkinsci.plugins.docker.commons.credentials.DockerServerEndpoint import com.nirima.jenkins.plugins.docker.DockerTemplate import com.nirima.jenkins.plugins.docker.DockerTemplateBase import com.nirima.jenkins.plugins.docker.launcher.AttachedDockerComputerLauncher @@ -7,25 +9,27 @@ import jenkins.model.Jenkins // parameters def dockerTemplateBaseParameters = [ - bindAllPorts: false, - bindPorts: '', - cpuShares: null, + image: 'jenkinsci/slave:latest', + pullCredentialsId: '', dnsString: '', + network: '', dockerCommand: '', + volumesString: '', + volumesFromString: '', environmentsString: '', - extraHostsString: '', hostname: '', - image: 'jenkinsci/slave:latest', - macAddress: '', + user: '', + extraGroupsString: '', memoryLimit: null, memorySwap: null, - network: '', + cpuShares: null, + shmSize: null, + bindPorts: '', + bindAllPorts: false, privileged: false, - pullCredentialsId: '', - sharedMemorySize: null, -  tty: true, - volumesFromString: '', - volumesString: '' + tty: true, + macAddress: '', + extraHostsString: '' ] def DockerTemplateParameters = [ @@ -45,30 +49,12 @@ def dockerCloudParameters = [ version: '' ] -// https://github.com/jenkinsci/docker-plugin/blob/docker-plugin-1.1.2/src/main/java/com/nirima/jenkins/plugins/docker/DockerTemplateBase.java -DockerTemplateBase dockerTemplateBase = new DockerTemplateBase( - dockerTemplateBaseParameters.image, - dockerTemplateBaseParameters.pullCredentialsId, - dockerTemplateBaseParameters.dnsString, - dockerTemplateBaseParameters.network, - dockerTemplateBaseParameters.dockerCommand, - dockerTemplateBaseParameters.volumesString, - dockerTemplateBaseParameters.volumesFromString, - dockerTemplateBaseParameters.environmentsString, - dockerTemplateBaseParameters.hostname, - dockerTemplateBaseParameters.memoryLimit, - dockerTemplateBaseParameters.memorySwap, - dockerTemplateBaseParameters.cpuShares, - dockerTemplateBaseParameters.sharedMemorySize, -  dockerTemplateBaseParameters.bindPorts, - dockerTemplateBaseParameters.bindAllPorts, - dockerTemplateBaseParameters.privileged, - dockerTemplateBaseParameters.tty, - dockerTemplateBaseParameters.macAddress, - dockerTemplateBaseParameters.extraHostsString -) +DockerTemplateBase dockerTemplateBase = new DockerTemplateBase(dockerTemplateBaseParameters.image) +dockerTemplateBaseParameters.findAll{ it.key != "image" }.each { + k, v -> + dockerTemplateBase."$k" = v +} -// https://github.com/jenkinsci/docker-plugin/blob/docker-plugin-1.1.2/src/main/java/com/nirima/jenkins/plugins/docker/DockerTemplate.java DockerTemplate dockerTemplate = new DockerTemplate( dockerTemplateBase, new DockerComputerAttachConnector(), @@ -77,17 +63,18 @@ DockerTemplate dockerTemplate = new DockerTemplate( DockerTemplateParameters.instanceCapStr ) -// https://github.com/jenkinsci/docker-plugin/blob/docker-plugin-1.1.2/src/main/java/com/nirima/jenkins/plugins/docker/DockerCloud.java +dockerApi = new DockerAPI(new DockerServerEndpoint(dockerCloudParameters.serverUrl, dockerCloudParameters.credentialsId)) +dockerApi.with { + connectTimeout = dockerCloudParameters.connectTimeout + readTimeout = dockerCloudParameters.readTimeout + apiVersion = dockerCloudParameters.version + hostname = dockerCloudParameters.dockerHostname +} + DockerCloud dockerCloud = new DockerCloud( dockerCloudParameters.name, - [dockerTemplate], - dockerCloudParameters.serverUrl, - dockerCloudParameters.containerCapStr, - dockerCloudParameters.connectTimeout, - dockerCloudParameters.readTimeout, - dockerCloudParameters.credentialsId, - dockerCloudParameters.version, - dockerCloudParameters.dockerHostname + dockerApi, + [dockerTemplate] ) // get Jenkins instance