Skip to content

Commit

Permalink
JENKINS-32363: Added forcePull to docker-custom-build-environment
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Whitcraft committed Jan 8, 2016
1 parent 45a2024 commit 5c0b8c2
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 4 deletions.
@@ -1,19 +1,23 @@
package javaposse.jobdsl.dsl.helpers.wrapper

import javaposse.jobdsl.dsl.Context
import javaposse.jobdsl.dsl.AbstractContext
import javaposse.jobdsl.dsl.JobManagement
import javaposse.jobdsl.dsl.RequiresPlugin

class BuildInDockerContext implements Context {
class BuildInDockerContext extends AbstractContext {
Node selector
String dockerHostURI
String serverCredentials
String registryCredentials
List<Node> volumes = []
boolean privilegedMode
boolean verbose
boolean forcePull
String userGroup
String startCommand = '/bin/cat'

BuildInDockerContext() {
BuildInDockerContext(JobManagement jobManagement) {
super(jobManagement)
dockerfile()
}

Expand Down Expand Up @@ -59,6 +63,16 @@ class BuildInDockerContext implements Context {
this.verbose = verbose
}

/***
* Always pull the image from the repository. Defaults to {@code false}.
*
* @since 1.4.3
*/
@RequiresPlugin(id = 'docker-custom-build-environment', minimumVersion = '1.6.2')
void forcePull(boolean forcePull = true) {
this.forcePull = forcePull
}

void userGroup(String userGroup) {
this.userGroup = userGroup
}
Expand Down
Expand Up @@ -564,7 +564,7 @@ class WrapperContext extends AbstractExtensibleContext {
*/
@RequiresPlugin(id = 'docker-custom-build-environment', minimumVersion = '1.5.1')
void buildInDocker(@DslContext(BuildInDockerContext) Closure closure) {
BuildInDockerContext context = new BuildInDockerContext()
BuildInDockerContext context = new BuildInDockerContext(jobManagement)
ContextHelper.executeInContext(closure, context)

Node node = new NodeBuilder().'com.cloudbees.jenkins.plugins.okidocki.DockerBuildWrapper' {
Expand All @@ -580,6 +580,11 @@ class WrapperContext extends AbstractExtensibleContext {
verbose(context.verbose)
volumes(context.volumes)
privileged(context.privilegedMode)
if (jobManagement.getPluginVersion('docker-custom-build-environment')?.isNewerThan(
new VersionNumber('1.6.1'))
) {
forcePull(context.forcePull)
}
group(context.userGroup ?: '')
command(context.startCommand ?: '')
}
Expand Down
Expand Up @@ -1362,4 +1362,50 @@ class WrapperContextSpec extends Specification {
}
1 * mockJobManagement.requireMinimumPluginVersion('docker-custom-build-environment', '1.5.1')
}

def 'buildInDocker with no options with 1.6.2'() {
setup:
mockJobManagement.getPluginVersion('docker-custom-build-environment') >> new VersionNumber('1.6.2')

when:
context.buildInDocker {
image('test1')
dockerHostURI('test3')
serverCredentials('test4')
registryCredentials('test5')
volume('test6', 'test7')
volume('test8', 'test9')
privilegedMode()
verbose()
forcePull()
userGroup('test10')
startCommand('test11')
}

then:
with(context.wrapperNodes[0]) {
name() == 'com.cloudbees.jenkins.plugins.okidocki.DockerBuildWrapper'
children().size() == 9
selector[0].children().size() == 1
selector[0].attribute('class') == 'com.cloudbees.jenkins.plugins.okidocki.PullDockerImageSelector'
selector[0].image[0].value() == 'test1'
dockerHost[0].children().size() == 2
dockerHost[0].uri[0].value() == 'test3'
dockerHost[0].credentialsId[0].value() == 'test4'
dockerRegistryCredentials[0].value() == 'test5'
verbose[0].value() == true
volumes[0].children().size() == 2
volumes[0].'com.cloudbees.jenkins.plugins.okidocki.Volume'[0].children().size() == 2
volumes[0].'com.cloudbees.jenkins.plugins.okidocki.Volume'[0].hostPath[0].value() == 'test6'
volumes[0].'com.cloudbees.jenkins.plugins.okidocki.Volume'[0].path[0].value() == 'test7'
volumes[0].'com.cloudbees.jenkins.plugins.okidocki.Volume'[1].children().size() == 2
volumes[0].'com.cloudbees.jenkins.plugins.okidocki.Volume'[1].hostPath[0].value() == 'test8'
volumes[0].'com.cloudbees.jenkins.plugins.okidocki.Volume'[1].path[0].value() == 'test9'
privileged[0].value() == true
forcePull[0].value() == true
group[0].value() == 'test10'
command[0].value() == 'test11'
}
1 * mockJobManagement.requireMinimumPluginVersion('docker-custom-build-environment', '1.6.2')
}
}

0 comments on commit 5c0b8c2

Please sign in to comment.