Skip to content

Commit

Permalink
enhanced support for the Pipeline Multibranch Plugin
Browse files Browse the repository at this point in the history
[FIXES JENKINS-43693]
  • Loading branch information
daspilker committed Apr 29, 2017
1 parent 7a0ec11 commit 1bd2d95
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
3 changes: 3 additions & 0 deletions docs/Home.md
Expand Up @@ -31,6 +31,9 @@ Browse the Jenkins issue tracker to see any [open issues](https://issues.jenkins
* 1.62 (unreleased)
* Show enum values for generated DSL in embedded API viewer
[#1020](https://github.com/jenkinsci/job-dsl-plugin/pull/1020)
* Enhanced support for the
[Pipeline Multibranch Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Multibranch+Plugin)
([JENKINS-43693](https://issues.jenkins-ci.org/browse/JENKINS-43693))
* 1.61 (April 17 2017)
* Enhanced support for the [Stash Notifier Plugin](https://wiki.jenkins-ci.org/display/JENKINS/StashNotifier+Plugin)
([JENKINS-42900](https://issues.jenkins-ci.org/browse/JENKINS-42900),
Expand Down
Expand Up @@ -31,7 +31,7 @@ class BranchSourcesContext extends AbstractExtensibleContext {

branchSourceNodes << new NodeBuilder().'jenkins.branch.BranchSource' {
source(class: 'jenkins.plugins.git.GitSCMSource') {
id(UUID.randomUUID())
id(context.id)
remote(context.remote ?: '')
credentialsId(context.credentialsId ?: '')
includes(context.includes ?: '')
Expand All @@ -58,7 +58,7 @@ class BranchSourcesContext extends AbstractExtensibleContext {

branchSourceNodes << new NodeBuilder().'jenkins.branch.BranchSource' {
source(class: 'org.jenkinsci.plugins.github_branch_source.GitHubSCMSource') {
id(UUID.randomUUID())
id(context.id)
if (context.apiUri) {
apiUri(context.apiUri)
}
Expand Down
Expand Up @@ -3,12 +3,22 @@ package javaposse.jobdsl.dsl.helpers.workflow
import javaposse.jobdsl.dsl.Context

class GitBranchSourceContext implements Context {
String id = UUID.randomUUID()
String remote
String credentialsId
String includes = '*'
String excludes
boolean ignoreOnPushNotifications

/**
* Specifies a unique ID for this branch source.
*
* @since 1.62
*/
void id(String id) {
this.id = id
}

/**
* Sets the Git remote repository URL.
*/
Expand Down
Expand Up @@ -5,6 +5,7 @@ import javaposse.jobdsl.dsl.JobManagement
import javaposse.jobdsl.dsl.RequiresPlugin

class GitHubBranchSourceContext extends AbstractContext {
String id = UUID.randomUUID()
String apiUri
String scanCredentialsId
String checkoutCredentialsId = 'SAME'
Expand All @@ -23,6 +24,15 @@ class GitHubBranchSourceContext extends AbstractContext {
super(jobManagement)
}

/**
* Specifies a unique ID for this branch source.
*
* @since 1.62
*/
void id(String id) {
this.id = id
}

/**
* Sets the GitHub API URI. Defaults to GitHub.
*/
Expand Down
Expand Up @@ -30,7 +30,7 @@ class BranchSourcesContextsSpec extends Specification {
children().size() == 2
with(source[0]) {
children().size() == 6
id[0].value() instanceof UUID
id[0].value() instanceof String
remote[0].value().empty
credentialsId[0].value().empty
includes[0].value() == '*'
Expand All @@ -50,6 +50,7 @@ class BranchSourcesContextsSpec extends Specification {
def 'git with all options'() {
when:
context.git {
id('test')
remote('foo')
credentialsId('bar')
includes('lorem')
Expand All @@ -64,7 +65,7 @@ class BranchSourcesContextsSpec extends Specification {
children().size() == 2
with(source[0]) {
children().size() == 6
id[0].value() instanceof UUID
id[0].value() == 'test'
remote[0].value() == 'foo'
credentialsId[0].value() == 'bar'
includes[0].value() == 'lorem'
Expand Down Expand Up @@ -92,7 +93,7 @@ class BranchSourcesContextsSpec extends Specification {
children().size() == 2
with(source[0]) {
children().size() == 7
id[0].value() instanceof UUID
id[0].value() instanceof String
scanCredentialsId[0].value().empty
checkoutCredentialsId[0].value() == 'SAME'
repoOwner[0].value().empty
Expand All @@ -114,6 +115,7 @@ class BranchSourcesContextsSpec extends Specification {
def 'github with all options'() {
when:
context.github {
id('test')
apiUri('https://custom.url')
scanCredentialsId('scanCreds')
checkoutCredentialsId('checkoutCreds')
Expand All @@ -131,7 +133,7 @@ class BranchSourcesContextsSpec extends Specification {
children().size() == 2
with(source[0]) {
children().size() == 8
id[0].value() instanceof UUID
id[0].value() == 'test'
apiUri[0].value() == 'https://custom.url'
scanCredentialsId[0].value() == 'scanCreds'
checkoutCredentialsId[0].value() == 'checkoutCreds'
Expand Down Expand Up @@ -166,7 +168,7 @@ class BranchSourcesContextsSpec extends Specification {
children().size() == 2
with(source[0]) {
children().size() == 13
id[0].value() instanceof UUID
id[0].value() instanceof String
scanCredentialsId[0].value().empty
checkoutCredentialsId[0].value() == 'SAME'
repoOwner[0].value().empty
Expand Down Expand Up @@ -197,6 +199,7 @@ class BranchSourcesContextsSpec extends Specification {

when:
context.github {
id('test')
apiUri('https://custom.url')
scanCredentialsId('scanCreds')
checkoutCredentialsId('checkoutCreds')
Expand All @@ -220,7 +223,7 @@ class BranchSourcesContextsSpec extends Specification {
children().size() == 2
with(source[0]) {
children().size() == 14
id[0].value() instanceof UUID
id[0].value() == 'test'
apiUri[0].value() == 'https://custom.url'
scanCredentialsId[0].value() == 'scanCreds'
checkoutCredentialsId[0].value() == 'checkoutCreds'
Expand Down

0 comments on commit 1bd2d95

Please sign in to comment.