Skip to content
Permalink
Browse files

Merge remote-tracking branch 'rgal/JENKINS-32391'

  • Loading branch information
daspilker committed Feb 15, 2016
2 parents 7ba339b + ef47dbf commit 0e14c7f9902288460d414e48d2e60983867b2554
@@ -23,6 +23,8 @@ Browse the Jenkins issue tracker to see any [open issues](https://issues.jenkins
* 1.44 (unreleased)
* 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))
* Added support for the [P4 Plugin](https://wiki.jenkins-ci.org/display/JENKINS/P4+Plugin)
([JENKINS-32391](https://issues.jenkins-ci.org/browse/JENKINS-32391))
* Enhanced support for the
[Lockable Resources Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Lockable+Resources+Plugin)
([JENKINS-32906](https://issues.jenkins-ci.org/browse/JENKINS-32906))
@@ -0,0 +1,12 @@
job('example') {
scm {
perforceP4('p4_credentials') {
workspace {
manual('ws_name', '//depot/Tools/build/... //ws_name/build/...')
}
configure { node ->
node / workspace / spec / clobber('true')
}
}
}
}
@@ -8,6 +8,7 @@ import javaposse.jobdsl.dsl.WithXmlAction
import javaposse.jobdsl.dsl.helpers.scm.ClearCaseContext
import javaposse.jobdsl.dsl.helpers.scm.GitContext
import javaposse.jobdsl.dsl.helpers.scm.HgContext
import javaposse.jobdsl.dsl.helpers.scm.P4Context
import javaposse.jobdsl.dsl.helpers.scm.PerforcePasswordEncryptor
import javaposse.jobdsl.dsl.helpers.scm.RTCContext
import javaposse.jobdsl.dsl.helpers.scm.SvnContext
@@ -373,6 +374,44 @@ class ScmContext extends AbstractExtensibleContext {
scmNodes << p4Node
}

/**
* Add Perforce SCM source using Perforce p4 plugin.
*
* This must use Jenkins credentials.
*
* The configure block must be used to set additional options.
*
* @since 1.43
*/
@RequiresPlugin(id = 'p4', minimumVersion = '1.3.5')
void perforceP4(String credentials, @DslContext(P4Context) Closure p4Closure) {
checkNotNull(credentials, 'credentials must not be null')

P4Context p4Context = new P4Context()
executeInContext(p4Closure, p4Context)

Node p4Node = new NodeBuilder().scm(class: 'org.jenkinsci.plugins.p4.PerforceScm') {
credential(credentials)
populate(class: 'org.jenkinsci.plugins.p4.populate.AutoCleanImpl') {
have(true)
force(false)
modtime(false)
quiet(true)
pin()
replace(true)
delete(true)
}
}
p4Node.children().add(p4Context.workspaceContext.workspaceConfig)

if (p4Context.withXmlClosure) {
WithXmlAction action = new WithXmlAction(p4Context.withXmlClosure)
action.execute(p4Node)
}

scmNodes << p4Node
}

/**
* Add a SCM source which copies the workspace of another project.
*
@@ -0,0 +1,26 @@
package javaposse.jobdsl.dsl.helpers.scm

import javaposse.jobdsl.dsl.Context
import javaposse.jobdsl.dsl.ContextHelper
import javaposse.jobdsl.dsl.DslContext

class P4Context implements Context {
P4WorkspaceContext workspaceContext = new P4WorkspaceContext()
Closure withXmlClosure

/**
* Sets the appropriate Perforce workspace behaviour.
*/
void workspace(@DslContext(P4WorkspaceContext) Closure closure) {
ContextHelper.executeInContext(closure, workspaceContext)
}

/**
* Allows direct manipulation of the generated XML. The {@code scm} node is passed into the configure block.
*
* @see <a href="https://github.com/jenkinsci/job-dsl-plugin/wiki/The-Configure-Block">The Configure Block</a>
*/
void configure(Closure withXmlClosure) {
this.withXmlClosure = withXmlClosure
}
}
@@ -0,0 +1,33 @@
package javaposse.jobdsl.dsl.helpers.scm

import javaposse.jobdsl.dsl.Context

class P4WorkspaceContext implements Context {
Node workspaceConfig

P4WorkspaceContext() {
manual('', '')
}

/**
* Set up a manual workspace with workspace name and view spec.
*/
void manual(String workspaceName, String viewSpec) {
workspaceConfig = new NodeBuilder().workspace(class: 'org.jenkinsci.plugins.p4.workspace.ManualWorkspaceImpl') {
charset('none')
pinHost(false)
name(workspaceName ?: '')
spec {
allwrite(false)
clobber(false)
compress(false)
locked(false)
modtime(false)
rmdir(false)
streamName()
line('LOCAL')
view(viewSpec ?: '')
}
}
}
}
@@ -1655,6 +1655,107 @@ class ScmContextSpec extends Specification {
(1.._) * mockJobManagement.requirePlugin('perforce')
}

def 'call perforceP4 with all options'() {
when:
context.perforceP4('p4-user-creds') {
workspace {
manual('ws', 'view')
}
configure { node ->
node / foo('bar')
}
}

then:
context.scmNodes[0] != null
with(context.scmNodes[0]) {
children().size() == 4
attributes()['class'] == 'org.jenkinsci.plugins.p4.PerforceScm'
credential[0].value() == 'p4-user-creds'
workspace.size() == 1
with(workspace[0]) {
children().size() == 4
attributes()['class'] == 'org.jenkinsci.plugins.p4.workspace.ManualWorkspaceImpl'
charset[0].value() == 'none'
pinHost[0].value() == false
name[0].value() == 'ws'
spec.size() == 1
with(spec[0]) {
children().size() == 9
allwrite[0].value() == false
clobber[0].value() == false
compress[0].value() == false
locked[0].value() == false
modtime[0].value() == false
rmdir[0].value() == false
streamName[0].value().empty
line[0].value() == 'LOCAL'
view[0].value() == 'view'
}
}
with(populate[0]) {
children().size() == 7
attributes()['class'] == 'org.jenkinsci.plugins.p4.populate.AutoCleanImpl'
have[0].value() == true
force[0].value() == false
modtime[0].value() == false
quiet[0].value() == true
pin[0].value().empty
replace[0].value() == true
delete[0].value() == true
}
foo[0].value() == 'bar'
}
1 * mockJobManagement.requireMinimumPluginVersion('p4', '1.3.5')
}

def 'call perforcep4 with no options'() {
when:
context.perforceP4('p4-user-creds') {
}

then:
context.scmNodes[0] != null
with(context.scmNodes[0]) {
children().size() == 3
attributes()['class'] == 'org.jenkinsci.plugins.p4.PerforceScm'
credential[0].value() == 'p4-user-creds'
workspace.size() == 1
with(workspace[0]) {
children().size() == 4
attributes()['class'] == 'org.jenkinsci.plugins.p4.workspace.ManualWorkspaceImpl'
charset[0].value() == 'none'
pinHost[0].value() == false
name[0].value().empty
spec.size() == 1
with(spec[0]) {
children().size() == 9
allwrite[0].value() == false
clobber[0].value() == false
compress[0].value() == false
locked[0].value() == false
modtime[0].value() == false
rmdir[0].value() == false
streamName[0].value().empty
line[0].value() == 'LOCAL'
view[0].value().empty
}
}
with(populate[0]) {
children().size() == 7
attributes()['class'] == 'org.jenkinsci.plugins.p4.populate.AutoCleanImpl'
have[0].value() == true
force[0].value() == false
modtime[0].value() == false
quiet[0].value() == true
pin[0].value().empty
replace[0].value() == true
delete[0].value() == true
}
}
1 * mockJobManagement.requireMinimumPluginVersion('p4', '1.3.5')
}

def 'call cloneWorkspace'(parentJob, criteria) {
when:
context.cloneWorkspace(parentJob, criteria)

0 comments on commit 0e14c7f

Please sign in to comment.
You can’t perform that action at this time.