Skip to content

Commit

Permalink
Merge remote-tracking branch 'pyther/gitlab'
Browse files Browse the repository at this point in the history
  • Loading branch information
daspilker committed May 24, 2016
2 parents 892a65b + 9c8fa50 commit b507a36
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 8 deletions.
4 changes: 4 additions & 0 deletions docs/Home.md
Expand Up @@ -43,6 +43,8 @@ Browse the Jenkins issue tracker to see any [open issues](https://issues.jenkins
([JENKINS-34720](https://issues.jenkins-ci.org/browse/JENKINS-34720))
* Enhanced support for the [Run Condition Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Run+Condition+Plugin)
([JENKINS-34941](https://issues.jenkins-ci.org/browse/JENKINS-34941))
* Enhanced support for the [Gitlab Plugin](https://wiki.jenkins-ci.org/display/JENKINS/GitLab+Plugin)
([JENKINS-34534](https://issues.jenkins-ci.org/browse/JENKINS-34534))
* Fixed support for the [Violations Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Violations)
([JENKINS-26086](https://issues.jenkins-ci.org/browse/JENKINS-26086))
* Support for the [Slack Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Slack+Plugin) is deprecated, see
Expand All @@ -51,6 +53,8 @@ Browse the Jenkins issue tracker to see any [open issues](https://issues.jenkins
* Support for [HipChat Plugin](https://wiki.jenkins-ci.org/display/JENKINS/HipChat+Plugin) is deprecated, see
[Migration](Migration#migrating-to-147)
([JENKINS-32502](https://issues.jenkins-ci.org/browse/JENKINS-32502))
* Support for the older versions of the [Gitlab Plugin](https://wiki.jenkins-ci.org/display/JENKINS/GitLab+Plugin) is
deprecated, see [Migration](Migration#migrating-to-147)
* Added `pipelineJob` and `multibranchPipelineJob` as replacements for `workflowJob` and `multibranchWorkflowJob`, see
[Migration](Migration#migrating-to-147)
([JENKINS-33325](https://issues.jenkins-ci.org/browse/JENKINS-33325))
Expand Down
5 changes: 5 additions & 0 deletions docs/Migration.md
Expand Up @@ -60,6 +60,11 @@ multibranchPipelineJob('example-2') {
}
```

### GitLab

Support for versions older than 1.2 of the [Gitlab Plugin](https://wiki.jenkins-ci.org/display/JENKINS/GitLab+Plugin) is
[[deprecated|Deprecation-Policy]] and will be removed.

### Slack

Support for the [Slack Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Slack+Plugin) is
Expand Down
Expand Up @@ -10,7 +10,6 @@ job('example') {
addVoteOnMergeRequest(false)
useCiFeatures(false)
acceptMergeRequestOnSuccess()
allowAllBranches(false)
includeBranches('include1,include2')
excludeBranches('exclude1,exclude2')
}
Expand Down
@@ -1,15 +1,19 @@
package javaposse.jobdsl.dsl.helpers.triggers

import javaposse.jobdsl.dsl.Context
import javaposse.jobdsl.dsl.AbstractContext
import javaposse.jobdsl.dsl.JobManagement
import javaposse.jobdsl.dsl.RequiresPlugin

import static javaposse.jobdsl.dsl.Preconditions.checkArgument

class GitLabTriggerContext implements Context {
class GitLabTriggerContext extends AbstractContext {
private static final Set<String> VALID_EXECUTION_STATUSES = ['never', 'source', 'both']

String includeBranches = ''
String excludeBranches = ''
String includeBranches
String excludeBranches
String targetBranchRegex
String rebuildOpenMergeRequest = 'never'
String branchFilterType = 'all'
boolean buildOnMergeRequestEvents = true
boolean buildOnPushEvents = true
boolean enableCiSkip = true
Expand All @@ -20,18 +24,37 @@ class GitLabTriggerContext implements Context {
boolean acceptMergeRequestOnSuccess = false
boolean allowAllBranches = false

GitLabTriggerContext(JobManagement jobManagement) {
super(jobManagement)
}

/**
* Comma-separated list of source branches allowed to trigger a build from a push event.
*/
void includeBranches(String includeBranches) {
this.includeBranches = includeBranches
this.branchFilterType = 'nameBasedFilter'
}

/**
* Comma-separated list of source branches disabled to trigger a build from a push event.
*/
void excludeBranches(String excludeBranches) {
this.excludeBranches = excludeBranches
this.branchFilterType = 'nameBasedFilter'
}

/**
* The target branch regex allows to limit the execution of this job to
* certain branches. Any branch matching the specified pattern triggers the
* job.
*
* @since 1.47
*/
@RequiresPlugin(id = 'gitlab-plugin', minimumVersion = '1.2.0')
void targetBranchRegex(String targetBranchRegex) {
this.targetBranchRegex = targetBranchRegex
this.branchFilterType = 'regexBasedFilter'
}

/**
Expand Down Expand Up @@ -93,6 +116,7 @@ class GitLabTriggerContext implements Context {
/**
* If set, ignores filtered branches. Defaults to {@code false}.
*/
@Deprecated
void allowAllBranches(boolean allowAllBranches = true) {
this.allowAllBranches = allowAllBranches
}
Expand Down
Expand Up @@ -204,7 +204,9 @@ class TriggerContext extends ItemTriggerContext {
*/
@RequiresPlugin(id = 'gitlab-plugin', minimumVersion = '1.1.28')
void gitlabPush(@DslContext(GitLabTriggerContext) Closure closure) {
GitLabTriggerContext context = new GitLabTriggerContext()
jobManagement.logPluginDeprecationWarning('gitlab-plugin', '1.2.0')

GitLabTriggerContext context = new GitLabTriggerContext(jobManagement)
ContextHelper.executeInContext(closure, context)

triggerNodes << new NodeBuilder().'com.dabsquared.gitlabjenkins.GitLabPushTrigger' {
Expand All @@ -217,10 +219,15 @@ class TriggerContext extends ItemTriggerContext {
addNoteOnMergeRequest(context.addNoteOnMergeRequest)
addCiMessage(context.useCiFeatures)
addVoteOnMergeRequest(context.addVoteOnMergeRequest)
allowAllBranches(context.allowAllBranches)
includeBranchesSpec(context.includeBranches ?: '')
excludeBranchesSpec(context.excludeBranches ?: '')
acceptMergeRequestOnSuccess(context.acceptMergeRequestOnSuccess)
if (jobManagement.isMinimumPluginVersionInstalled('gitlab-plugin', '1.2.0')) {
branchFilterType(context.branchFilterType)
targetBranchRegex(context.targetBranchRegex ?: '')
} else {
allowAllBranches(context.allowAllBranches)
}
}
}

Expand Down
Expand Up @@ -376,9 +376,131 @@ class TriggerContextSpec extends Specification {
acceptMergeRequestOnSuccess[0].value() == false
}
1 * mockJobManagement.requireMinimumPluginVersion('gitlab-plugin', '1.1.28')
1 * mockJobManagement.logPluginDeprecationWarning('gitlab-plugin', '1.2.0')
}

def 'call gitlabPush trigger with all options'() {
def 'call gitlabPush trigger with no options, plugin version 1.2.x'() {
setup:
mockJobManagement.isMinimumPluginVersionInstalled('gitlab-plugin', '1.2.0') >> true

when:
context.gitlabPush {
}

then:
with(context.triggerNodes[0]) {
name() == 'com.dabsquared.gitlabjenkins.GitLabPushTrigger'
children().size() == 14
spec[0].value().empty
triggerOnPush[0].value() == true
triggerOnMergeRequest[0].value() == true
triggerOpenMergeRequestOnPush[0].value() == 'never'
ciSkip[0].value() == true
setBuildDescription[0].value() == true
addNoteOnMergeRequest[0].value() == true
addCiMessage[0].value() == false
addVoteOnMergeRequest[0].value() == true
branchFilterType[0].value() == 'all'
includeBranchesSpec[0].value().empty
excludeBranchesSpec[0].value().empty
targetBranchRegex[0].value().empty
acceptMergeRequestOnSuccess[0].value() == false
}
1 * mockJobManagement.requireMinimumPluginVersion('gitlab-plugin', '1.1.28')
1 * mockJobManagement.logPluginDeprecationWarning('gitlab-plugin', '1.2.0')
}

def 'call gitlabPush trigger with all options and name based filter'() {
setup:
mockJobManagement.isMinimumPluginVersionInstalled('gitlab-plugin', '1.2.0') >> true

when:
context.gitlabPush {
buildOnMergeRequestEvents(value)
buildOnPushEvents(value)
enableCiSkip(value)
setBuildDescription(value)
addNoteOnMergeRequest(value)
rebuildOpenMergeRequest('both')
addVoteOnMergeRequest(value)
useCiFeatures(value)
acceptMergeRequestOnSuccess(value)
includeBranches('include1,include2')
excludeBranches('exclude1,exclude2')
}

then:
with(context.triggerNodes[0]) {
name() == 'com.dabsquared.gitlabjenkins.GitLabPushTrigger'
children().size() == 14
spec[0].value().empty
triggerOnPush[0].value() == value
triggerOnMergeRequest[0].value() == value
triggerOpenMergeRequestOnPush[0].value() == 'both'
ciSkip[0].value() == value
setBuildDescription[0].value() == value
addNoteOnMergeRequest[0].value() == value
addCiMessage[0].value() == value
addVoteOnMergeRequest[0].value() == value
branchFilterType[0].value() == 'nameBasedFilter'
includeBranchesSpec[0].value() == 'include1,include2'
excludeBranchesSpec[0].value() == 'exclude1,exclude2'
targetBranchRegex[0].value().empty
acceptMergeRequestOnSuccess[0].value() == value
}
1 * mockJobManagement.requireMinimumPluginVersion('gitlab-plugin', '1.1.28')
1 * mockJobManagement.logPluginDeprecationWarning('gitlab-plugin', '1.2.0')

where:
value << [true, false]
}

def 'call gitlabPush trigger with all options and regex based filter'() {
setup:
mockJobManagement.isMinimumPluginVersionInstalled('gitlab-plugin', '1.2.0') >> true

when:
context.gitlabPush {
buildOnMergeRequestEvents(value)
buildOnPushEvents(value)
enableCiSkip(value)
setBuildDescription(value)
addNoteOnMergeRequest(value)
rebuildOpenMergeRequest('both')
addVoteOnMergeRequest(value)
useCiFeatures(value)
acceptMergeRequestOnSuccess(value)
targetBranchRegex('(.*debug.*|.*release.*)')
}

then:
with(context.triggerNodes[0]) {
name() == 'com.dabsquared.gitlabjenkins.GitLabPushTrigger'
children().size() == 14
spec[0].value().empty
triggerOnPush[0].value() == value
triggerOnMergeRequest[0].value() == value
triggerOpenMergeRequestOnPush[0].value() == 'both'
ciSkip[0].value() == value
setBuildDescription[0].value() == value
addNoteOnMergeRequest[0].value() == value
addCiMessage[0].value() == value
addVoteOnMergeRequest[0].value() == value
branchFilterType[0].value() == 'regexBasedFilter'
includeBranchesSpec[0].value().empty
excludeBranchesSpec[0].value().empty
targetBranchRegex[0].value() == '(.*debug.*|.*release.*)'
acceptMergeRequestOnSuccess[0].value() == value
}
1 * mockJobManagement.requireMinimumPluginVersion('gitlab-plugin', '1.1.28')
1 * mockJobManagement.requireMinimumPluginVersion('gitlab-plugin', '1.2.0')
1 * mockJobManagement.logPluginDeprecationWarning('gitlab-plugin', '1.2.0')

where:
value << [true, false]
}

def 'call gitlabPush trigger with all options, plugin version older than 1.2.0'() {
when:
context.gitlabPush {
buildOnMergeRequestEvents(value)
Expand Down Expand Up @@ -414,6 +536,8 @@ class TriggerContextSpec extends Specification {
acceptMergeRequestOnSuccess[0].value() == value
}
1 * mockJobManagement.requireMinimumPluginVersion('gitlab-plugin', '1.1.28')
1 * mockJobManagement.logPluginDeprecationWarning('gitlab-plugin', '1.2.0')
1 * mockJobManagement.logDeprecationWarning()

where:
value << [true, false]
Expand Down

0 comments on commit b507a36

Please sign in to comment.