Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-33782] Add support for the alternative SCM build choos…
…er strategy

Requires that the git-chooser-alternative jenkins plugin is installed at
v1.1 or higher.

:memo: Add documentation and release notes around the new alternative strategy
:white_check_mark: Add specs for the alternative build chooser extension
  • Loading branch information
erran committed Mar 24, 2016
1 parent 9eea45c commit 0ff5837
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/Home.md
Expand Up @@ -63,6 +63,7 @@ Browse the Jenkins issue tracker to see any [open issues](https://issues.jenkins
([#747](https://github.com/jenkinsci/job-dsl-plugin/pull/747))
* Deprecated a method for the [EnvInject Plugin](https://wiki.jenkins-ci.org/display/JENKINS/EnvInject+Plugin), see
[Migration](Migration#migrating-to-145)
* Add support for the [Git Chooser Alternative Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Git+Chooser+Alternative+Plugin) plugin. ([JENKINS-33782](https://issues.jenkins-ci.org/browse/JENKINS-33782) + [jenkinsci/job-dsl-plugin#801](https://github.com/jenkinsci/job-dsl-plugin/pull/801))
* 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
Expand Up @@ -59,3 +59,21 @@ job('example-4') {
}
}
}

// checkout repo at a specific branch using the alternative build choosing strategy.
job('example-1') {
scm {
git {
branches('branch-that-may-not-exist', 'master')
remote {
github('account/repo', 'ssh')
}
extensions {
choosingStrategy {
// Default to "master" if "branch-that-may-not-exist" does not exist.
alternative()
}
}
}
}
}
Expand Up @@ -41,4 +41,16 @@ class StrategyContext extends AbstractContext {
ancestorCommitSha1(commit)
}
}

/**
* Selects branches in priority order based on which branch exists.
*
* @since 1.45
*/
@RequiresPlugin(id = 'git-chooser-alternative', minimumVersion = '1.1')
void alternative() {
buildChooser = NodeBuilder.newInstance().buildChooser(
class: 'org.jenkinsci.plugins.git.chooser.alternative.AlternativeBuildChooser'
)
}
}
Expand Up @@ -1217,6 +1217,32 @@ class ScmContextSpec extends Specification {
1 * mockJobManagement.requireMinimumPluginVersion('git', '2.3.1')
}

def 'call git scm with alternative build chooser extension'() {
when:
context.git {
remote {
url('https://github.com/jenkinsci/job-dsl-plugin.git')
}
extensions {
choosingStrategy {
alternative()
}
}
}

then:
context.scmNodes[0] != null
context.scmNodes[0].extensions.size() == 1
context.scmNodes[0].extensions[0].'hudson.plugins.git.extensions.impl.BuildChooserSetting'.size() == 1
with(context.scmNodes[0].extensions[0].'hudson.plugins.git.extensions.impl.BuildChooserSetting'[0]) {
children().size() == 1
buildChooser[0].attribute('class') ==
'org.jenkinsci.plugins.git.chooser.alternative.AlternativeBuildChooser'
}
1 * mockJobManagement.requireMinimumPluginVersion('git', '2.2.6')
1 * mockJobManagement.requireMinimumPluginVersion('git-chooser-alternative', '1.1')
}

def 'call git scm with gerrit trigger build chooser extension'() {
when:
context.git {
Expand Down

0 comments on commit 0ff5837

Please sign in to comment.