Skip to content

Commit

Permalink
[JENKINS-32391] Basic implementation of Perforce P4 plugin support.
Browse files Browse the repository at this point in the history
  • Loading branch information
galloprussell committed Jan 13, 2016
1 parent bc346eb commit c0f637f
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/Home.md
Expand Up @@ -21,6 +21,8 @@ Browse the Jenkins issue tracker to see any [open issues](https://issues.jenkins

## Release Notes
* 1.43 (unreleased)
* 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))
* Added support for the [Clover PHP Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Clover+PHP+Plugin)
([JENKINS-31557](https://issues.jenkins-ci.org/browse/JENKINS-31557))
* Allow `BuildParametersContext` to be extended
Expand Down
@@ -0,0 +1,18 @@
job('example-1') {
scm {
perforcep4('p4_credentials') {
manual('ws_name', '//depot/Tools/build //ws_name/build')
}
}
}

job('example-2') {
scm {
perforcep4('p4_credentials') {
manual('ws_name', '//depot/Tools/build //ws_name/build')
configure { node ->
node / workspace / spec / clobber('true')
}
}
}
}
Expand Up @@ -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
Expand Down Expand Up @@ -389,6 +390,52 @@ class ScmContext extends AbstractExtensibleContext {
scmNodes << p4Node
}

/**
* Add Perforce SCM source using Perforce p4 plugin
*
* This must use Jenkins credentials.
*
* The closure parameter expects a configure block for direct manipulation of the generated XML. The {@code scm}
* node is passed into the configure block.
*
* 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(jobManagement)
executeInContext(p4Closure, p4Context)

Node p4Node = new NodeBuilder().scm(class: 'org.jenkinsci.plugins.p4.PerforceScm') {
credential credentials
}

if (p4Context.workspaceConfig) {
p4Node.children().add(p4Context.workspaceConfig)
}

Node populateNode = new NodeBuilder().populate(class: 'org.jenkinsci.plugins.p4.populate.AutoCleanImpl') {
have 'true'
force 'false'
modtime 'false'
quiet 'true'
pin ''
replace 'true'
delete 'true'
}
p4Node.children().add(populateNode)

// Apply Context
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.
*
Expand Down
@@ -0,0 +1,49 @@
package javaposse.jobdsl.dsl.helpers.scm

import javaposse.jobdsl.dsl.AbstractContext
import javaposse.jobdsl.dsl.JobManagement

import static javaposse.jobdsl.dsl.Preconditions.checkNotNull

class P4Context extends AbstractContext {

Node workspaceConfig
Closure withXmlClosure

P4Context(JobManagement jobManagement) {
super(jobManagement)
}

/**
* Set up a manual workspace with workspace name and viewspec.
*/
void manual(String workspaceName, String viewspec) {
checkNotNull(workspaceName, 'workspaceName must not be null')
checkNotNull(viewspec, 'viewspec must not be null')

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
}
}
}

/**
* Allows direct manipulation of the generated XML. The {@code scm} node is passed into the configure block.
*
*/
void configure(Closure withXmlClosure) {
this.withXmlClosure = withXmlClosure
}
}
Expand Up @@ -1993,6 +1993,73 @@ class ScmContextSpec extends Specification {
(1.._) * mockJobManagement.requirePlugin('perforce')
}

def 'call perforcep4 with manual workspace'() {
when:
context.perforcep4('p4-user-creds') {
manual('ws', '//depot/Tools/build/...\n//ws/webapplications/helloworld/...')
}

then:
context.scmNodes[0] != null
with(context.scmNodes[0]) {
attributes()['class'] == 'org.jenkinsci.plugins.p4.PerforceScm'
credential[0].value() == 'p4-user-creds'
workspace.size() == 1
with(workspace[0]) {
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]) {
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() == ''
line[0].value() == 'LOCAL'
view[0].value() == '//depot/Tools/build/...\n//ws/webapplications/helloworld/...'
}
}
with(populate[0]) {
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() == ''
replace[0].value() == 'true'
delete[0].value() == 'true'
}
}
1 * mockJobManagement.requireMinimumPluginVersion('p4', '1.3.5')
}

def 'call perforcep4 with manual workspace and configure'() {
when:
context.perforcep4('p4-user-creds') {
manual('ws', '//depot/Tools/build/...\n//ws/webapplications/helloworld/...')
configure { node ->
node / workspace / spec / clobber('true')
}
}

then:
context.scmNodes[0] != null
with(context.scmNodes[0]) {
workspace.size() == 1
with(workspace[0]) {
spec.size() == 1
with(spec[0]) {
clobber[0].value() == 'true'
}
}
}
1 * mockJobManagement.requireMinimumPluginVersion('p4', '1.3.5')
}

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

0 comments on commit c0f637f

Please sign in to comment.