Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #990 from daspilker/JENKINS-41485
[JENKINS-41485] enhanced support for the GitLab Plugin
  • Loading branch information
daspilker committed Jan 31, 2017
2 parents 62306c7 + c3d89c3 commit 32664e5
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 13 deletions.
4 changes: 4 additions & 0 deletions docs/Home.md
Expand Up @@ -32,6 +32,8 @@ Browse the Jenkins issue tracker to see any [open issues](https://issues.jenkins
([JENKINS-33630](https://issues.jenkins-ci.org/browse/JENKINS-33630),
[JENKINS-39754](https://issues.jenkins-ci.org/browse/JENKINS-39754),
[JENKINS-40719](https://issues.jenkins-ci.org/browse/JENKINS-40719))
* Enhanced support for the [GitLab Plugin](https://wiki.jenkins-ci.org/display/JENKINS/GitLab+Plugin)
([JENKINS-41485](https://issues.jenkins-ci.org/browse/JENKINS-41485))
* Fixed a problem with the plugin's dependencies
([JENKINS-41001](https://issues.jenkins-ci.org/browse/JENKINS-41001))
* Improved error message for invalid enum values
Expand All @@ -41,6 +43,8 @@ Browse the Jenkins issue tracker to see any [open issues](https://issues.jenkins
* The syntax for creating config files is changing, see [Migration](Migration#migrating-to-158)
* Most classes and related methods for creating config files are deprecated, see
[Migration](Migration#migrating-to-158)
* 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-158)
* 1.57 (January 15 2017)
* Updated optional
[Config File Provider Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Config+File+Provider+Plugin) dependency to
Expand Down
5 changes: 5 additions & 0 deletions docs/Migration.md
Expand Up @@ -169,6 +169,11 @@ The classes `javaposse.jobdsl.dsl.Config`, `javaposse.jobdsl.dsl.ConfigFile`,
`getConfigFileId` in `javaposse.jobdsl.dsl.JobManagement` and it's implementing classes are
[[deprecated|Deprecation-Policy]] and will be removed.

### GitLab

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

## Migrating to 1.57

### Rbenv
Expand Down
Expand Up @@ -5,11 +5,7 @@ job('example') {
buildOnPushEvents(false)
enableCiSkip(false)
setBuildDescription(false)
addNoteOnMergeRequest(false)
rebuildOpenMergeRequest('never')
addVoteOnMergeRequest(false)
useCiFeatures(false)
acceptMergeRequestOnSuccess()
includeBranches('include1,include2')
excludeBranches('exclude1,exclude2')
}
Expand Down
Expand Up @@ -2,6 +2,7 @@ package javaposse.jobdsl.dsl.helpers.triggers

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

import static javaposse.jobdsl.dsl.Preconditions.checkArgument

Expand All @@ -21,7 +22,8 @@ class GitLabTriggerContext extends AbstractContext {
boolean addVoteOnMergeRequest = true
boolean useCiFeatures = false
boolean acceptMergeRequestOnSuccess = false
boolean allowAllBranches = false
String noteRegex = 'Jenkins please retry a build'
boolean skipWorkInProgressMergeRequest = true

GitLabTriggerContext(JobManagement jobManagement) {
super(jobManagement)
Expand Down Expand Up @@ -86,39 +88,35 @@ class GitLabTriggerContext extends AbstractContext {
/**
* If set, adds a note with build status on merge requests. Defaults to {@code true}.
*/
@Deprecated
void addNoteOnMergeRequest(boolean addNoteOnMergeRequest = true) {
this.addNoteOnMergeRequest = addNoteOnMergeRequest
}

/**
* If set, adds a vote to note with build status on merge requests. Defaults to {@code true}.
*/
@Deprecated
void addVoteOnMergeRequest(boolean addVoteOnMergeRequest = true) {
this.addVoteOnMergeRequest = addVoteOnMergeRequest
}

/**
* If set, enables GitLab 8.1 CI features. Defaults to {@code false}.
*/
@Deprecated
void useCiFeatures(boolean useCiFeatures = true) {
this.useCiFeatures = useCiFeatures
}

/**
* If set, accepts merge request on success. Defaults to {@code false}.
*/
@Deprecated
void acceptMergeRequestOnSuccess(boolean acceptMergeRequestOnSuccess = true) {
this.acceptMergeRequestOnSuccess = acceptMergeRequestOnSuccess
}

/**
* If set, ignores filtered branches. Defaults to {@code false}.
*/
@Deprecated
void allowAllBranches(boolean allowAllBranches = true) {
this.allowAllBranches = allowAllBranches
}

/**
* Only rebuild open Merge Requests. Defaults to {@code 'never'}.
*
Expand All @@ -131,4 +129,24 @@ class GitLabTriggerContext extends AbstractContext {
)
this.rebuildOpenMergeRequest = rebuildOpenMergeRequest
}

/**
* When filled, commenting this phrase in the merge request will trigger a build.
*
* @since 1.58
*/
@RequiresPlugin(id = 'gitlab-plugin', minimumVersion = '1.2.4')
void commentTrigger(String commentTrigger) {
this.noteRegex = commentTrigger
}

/**
* If set, ignores work in progress pull requests.
*
* @since 1.58
*/
@RequiresPlugin(id = 'gitlab-plugin', minimumVersion = '1.2.4')
void skipWorkInProgressMergeRequest(boolean skipWorkInProgressMergeRequest = true) {
this.skipWorkInProgressMergeRequest = skipWorkInProgressMergeRequest
}
}
Expand Up @@ -208,6 +208,8 @@ class TriggerContext extends ItemTriggerContext {
*/
@RequiresPlugin(id = 'gitlab-plugin', minimumVersion = '1.2.0')
void gitlabPush(@DslContext(GitLabTriggerContext) Closure closure) {
jobManagement.logPluginDeprecationWarning('gitlab-plugin', '1.4.0')

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

Expand All @@ -226,6 +228,11 @@ class TriggerContext extends ItemTriggerContext {
acceptMergeRequestOnSuccess(context.acceptMergeRequestOnSuccess)
branchFilterType(context.branchFilterType)
targetBranchRegex(context.targetBranchRegex ?: '')
if (jobManagement.isMinimumPluginVersionInstalled('gitlab-plugin', '1.2.4')) {
triggerOnNoteRequest(context.noteRegex as boolean)
noteRegex(context.noteRegex ?: '')
skipWorkInProgressMergeRequest(context.skipWorkInProgressMergeRequest)
}
}
}

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

def 'call gitlabPush trigger with no options and newer plugin version'() {
setup:
mockJobManagement.isMinimumPluginVersionInstalled('gitlab-plugin', '1.2.4') >> true

when:
context.gitlabPush {
}

then:
with(context.triggerNodes[0]) {
name() == 'com.dabsquared.gitlabjenkins.GitLabPushTrigger'
children().size() == 17
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
triggerOnNoteRequest[0].value() == true
noteRegex[0].value() == 'Jenkins please retry a build'
skipWorkInProgressMergeRequest[0].value() == true
}
1 * mockJobManagement.requireMinimumPluginVersion('gitlab-plugin', '1.2.0')
1 * mockJobManagement.logPluginDeprecationWarning('gitlab-plugin', '1.4.0')
}

def 'call gitlabPush trigger with all options and name based filter'() {
Expand Down Expand Up @@ -417,6 +452,59 @@ class TriggerContextSpec extends Specification {
acceptMergeRequestOnSuccess[0].value() == value
}
1 * mockJobManagement.requireMinimumPluginVersion('gitlab-plugin', '1.2.0')
1 * mockJobManagement.logPluginDeprecationWarning('gitlab-plugin', '1.4.0')
4 * mockJobManagement.logDeprecationWarning()

where:
value << [true, false]
}

def 'call gitlabPush trigger with all options, name based filter and newer plugin version'() {
setup:
mockJobManagement.isMinimumPluginVersionInstalled('gitlab-plugin', '1.2.4') >> 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')
commentTrigger(null)
skipWorkInProgressMergeRequest(value)
}

then:
with(context.triggerNodes[0]) {
name() == 'com.dabsquared.gitlabjenkins.GitLabPushTrigger'
children().size() == 17
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
triggerOnNoteRequest[0].value() == false
noteRegex[0].value() == ''
skipWorkInProgressMergeRequest[0].value() == value
}
1 * mockJobManagement.requireMinimumPluginVersion('gitlab-plugin', '1.2.0')
1 * mockJobManagement.logPluginDeprecationWarning('gitlab-plugin', '1.4.0')
4 * mockJobManagement.logDeprecationWarning()

where:
value << [true, false]
Expand Down Expand Up @@ -457,6 +545,8 @@ class TriggerContextSpec extends Specification {
acceptMergeRequestOnSuccess[0].value() == value
}
1 * mockJobManagement.requireMinimumPluginVersion('gitlab-plugin', '1.2.0')
1 * mockJobManagement.logPluginDeprecationWarning('gitlab-plugin', '1.4.0')
4 * mockJobManagement.logDeprecationWarning()

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

0 comments on commit 32664e5

Please sign in to comment.