Skip to content

Commit

Permalink
added support for docker-build-publish plugin version 1.2
Browse files Browse the repository at this point in the history
[FIXES JENKINS-33439]
  • Loading branch information
daspilker committed Mar 17, 2016
1 parent 888196f commit 5f14949
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 3 deletions.
3 changes: 3 additions & 0 deletions docs/Home.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ Browse the Jenkins issue tracker to see any [open issues](https://issues.jenkins
([#782](https://github.com/jenkinsci/job-dsl-plugin/pull/782))
* Enhanced support for the [Git Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin)
([#790](https://github.com/jenkinsci/job-dsl-plugin/pull/790))
* Enhanced support for the [CloudBees Docker Build and Publish
Plugin](https://wiki.jenkins-ci.org/display/JENKINS/CloudBees+Docker+Build+and+Publish+plugin)
([JENKINS-33439](https://issues.jenkins-ci.org/browse/JENKINS-33439))
* 1.44 (March 11 2016)
* Added support for the [Mattermost Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Mattermost+Plugin)
([JENKINS-32764](https://issues.jenkins-ci.org/browse/JENKINS-32764))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package javaposse.jobdsl.dsl.helpers.step

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

class DockerBuildAndPublishContext implements Context {
class DockerBuildAndPublishContext extends AbstractContext {
String repositoryName
String tag
String dockerHostURI
Expand All @@ -17,6 +19,13 @@ class DockerBuildAndPublishContext implements Context {
boolean skipDecorate
boolean skipTagAsLatest
String dockerfileDirectory
String buildContext
String additionalBuildArgs
boolean forceTag = true

DockerBuildAndPublishContext(JobManagement jobManagement) {
super(jobManagement)
}

/**
* Specifies the name of the repository to build.
Expand Down Expand Up @@ -115,4 +124,34 @@ class DockerBuildAndPublishContext implements Context {
void dockerfileDirectory(String dockerfileDirectory) {
this.dockerfileDirectory = dockerfileDirectory
}

/**
* Specifies the project root path for the build. Defaults to the workspace root if not specified.
*
* @since 1.45
*/
@RequiresPlugin(id = 'docker-build-publish', minimumVersion = '1.2')
void buildContext(String buildContext) {
this.buildContext = buildContext
}

/**
* Specifies additional build arguments passed to docker build.
*
* @since 1.45
*/
@RequiresPlugin(id = 'docker-build-publish', minimumVersion = '1.2')
void additionalBuildArgs(String additionalBuildArgs) {
this.additionalBuildArgs = additionalBuildArgs
}

/**
* If set, forces tag replacement when tag already exists. Defaults to {@code true}.
*
* @since 1.45
*/
@RequiresPlugin(id = 'docker-build-publish', minimumVersion = '1.2')
void forceTag(boolean forceTag = true) {
this.forceTag = forceTag
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ class StepContext extends AbstractExtensibleContext {
*/
@RequiresPlugin(id = 'docker-build-publish', minimumVersion = '1.0')
void dockerBuildAndPublish(@DslContext(DockerBuildAndPublishContext) Closure closure) {
DockerBuildAndPublishContext context = new DockerBuildAndPublishContext()
DockerBuildAndPublishContext context = new DockerBuildAndPublishContext(jobManagement)
ContextHelper.executeInContext(closure, context)

stepNodes << new NodeBuilder().'com.cloudbees.dockerpublish.DockerBuilder' {
Expand Down Expand Up @@ -1002,6 +1002,11 @@ class StepContext extends AbstractExtensibleContext {
skipPush(context.skipPush)
createFingerprint(context.createFingerprints)
skipTagLatest(context.skipTagAsLatest)
if (jobManagement.isMinimumPluginVersionInstalled('docker-build-publish', '1.2')) {
buildContext(context.buildContext ?: '')
buildAdditionalArgs(context.additionalBuildArgs ?: '')
forceTag(context.forceTag)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3298,6 +3298,91 @@ class StepContextSpec extends Specification {
1 * jobManagement.requireMinimumPluginVersion('docker-build-publish', '1.0')
}

def 'call dockerBuildAndPublish with no options and version 1.2'() {
jobManagement.isMinimumPluginVersionInstalled('docker-build-publish', '1.2') >> true

when:
context.dockerBuildAndPublish {
}

then:
context.stepNodes.size() == 1
with(context.stepNodes[0]) {
name() == 'com.cloudbees.dockerpublish.DockerBuilder'
children().size() == 15
server[0].value().empty
registry[0].value().empty
repoName[0].value().empty
noCache[0].value() == false
forcePull[0].value() == true
dockerfilePath[0].value().empty
skipBuild[0].value() == false
skipDecorate[0].value() == false
repoTag[0].value().empty
skipPush[0].value() == false
createFingerprint[0].value() == true
skipTagLatest[0].value() == false
buildContext[0].value().empty
buildAdditionalArgs[0].value().empty
forceTag[0].value() == true
}
1 * jobManagement.requireMinimumPluginVersion('docker-build-publish', '1.0')
}

def 'call dockerBuildAndPublish with all options and version 1.2'() {
setup:
jobManagement.isMinimumPluginVersionInstalled('docker-build-publish', '1.2') >> true

when:
context.dockerBuildAndPublish {
repositoryName('test1')
tag('test2')
dockerHostURI('test3')
serverCredentials('test4')
dockerRegistryURL('test5')
registryCredentials('test6')
skipPush()
noCache()
forcePull(false)
skipBuild()
createFingerprints(false)
skipDecorate()
skipTagAsLatest()
dockerfileDirectory('test7')
buildContext('test8')
additionalBuildArgs('test9')
forceTag(false)
}

then:
context.stepNodes.size() == 1
with(context.stepNodes[0]) {
name() == 'com.cloudbees.dockerpublish.DockerBuilder'
children().size() == 15
server[0].children().size() == 2
server[0].uri[0].value() == 'test3'
server[0].credentialsId[0].value() == 'test4'
registry[0].children().size() == 2
registry[0].url[0].value() == 'test5'
registry[0].credentialsId[0].value() == 'test6'
repoName[0].value() == 'test1'
noCache[0].value() == true
forcePull[0].value() == false
dockerfilePath[0].value() == 'test7'
skipBuild[0].value() == true
skipDecorate[0].value() == true
repoTag[0].value() == 'test2'
skipPush[0].value() == true
createFingerprint[0].value() == false
skipTagLatest[0].value() == true
buildContext[0].value() == 'test8'
buildAdditionalArgs[0].value() == 'test9'
forceTag[0].value() == false
}
1 * jobManagement.requireMinimumPluginVersion('docker-build-publish', '1.0')
3 * jobManagement.requireMinimumPluginVersion('docker-build-publish', '1.2')
}

def 'call artifactDeployer with no options'() {
when:
context.artifactDeployer {
Expand Down

0 comments on commit 5f14949

Please sign in to comment.