Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to configure projectFactories for organization folders #1043

Merged
merged 2 commits into from
Oct 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package javaposse.jobdsl.dsl.helpers.workflow

import javaposse.jobdsl.dsl.AbstractExtensibleContext
import javaposse.jobdsl.dsl.ContextType
import javaposse.jobdsl.dsl.Item
import javaposse.jobdsl.dsl.JobManagement

@ContextType('jenkins.branch.MultiBranchProjectFactory')
class MultiBranchProjectFactoryContext extends AbstractExtensibleContext {
final List<Node> projectFactoryNodes = []

MultiBranchProjectFactoryContext(JobManagement jobManagement, Item item) {
super(jobManagement, item)
}

@Override
protected void addExtensionNode(final Node node) {
projectFactoryNodes << node
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import javaposse.jobdsl.dsl.ComputedFolder
import javaposse.jobdsl.dsl.ContextHelper
import javaposse.jobdsl.dsl.DslContext
import javaposse.jobdsl.dsl.JobManagement
import javaposse.jobdsl.dsl.helpers.workflow.MultiBranchProjectFactoryContext
import javaposse.jobdsl.dsl.helpers.workflow.ScmNavigatorsContext

/**
Expand All @@ -28,4 +29,23 @@ class OrganizationFolderJob extends ComputedFolder {
}
}
}

/**
* Sets the project factories for this folder.
*
* @since 1.65
*/
void projectFactories(@DslContext(MultiBranchProjectFactoryContext) Closure closure) {
MultiBranchProjectFactoryContext context =
new MultiBranchProjectFactoryContext(jobManagement, this)
ContextHelper.executeInContext(closure, context)

configure { Node project ->
Node factories = project / projectFactories
factories.children().clear()
context.projectFactoryNodes.each {
factories << it
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package javaposse.jobdsl.dsl.jobs

import javaposse.jobdsl.dsl.JobManagement
import javaposse.jobdsl.dsl.helpers.workflow.MultiBranchProjectFactoryContext
import javaposse.jobdsl.dsl.helpers.workflow.ScmNavigatorsContext
import spock.lang.Specification

Expand Down Expand Up @@ -131,4 +132,35 @@ class OrganizationFolderJobSpec extends Specification {
}
}
}

def 'can set the projectFactories'() {
setup:
jobManagement.callExtension('factory1', job, MultiBranchProjectFactoryContext, []) >>
new Node(null, 'org.example.MultiBranchProjectFactory1')
jobManagement.callExtension('factory2', job, MultiBranchProjectFactoryContext, []) >>
new Node(null, 'org.example.MultiBranchProjectFactory2')

when:
job.projectFactories {
factory1()
factory2()
factory1()
factory2()
factory2()
}

then:
with(job.node) {
projectFactories.size() == 1
with(projectFactories[0]) {
children().size() == 5
with(it.'org.example.MultiBranchProjectFactory1') {
size() == 2
}
with(it.'org.example.MultiBranchProjectFactory2') {
size() == 3
}
}
}
}
}