Skip to content

Commit 091dc0c

Browse files
committed
Merge branch 'JENKINS-27504'
2 parents 061b2cc + 69272f7 commit 091dc0c

File tree

5 files changed

+50
-21
lines changed

5 files changed

+50
-21
lines changed

docs/Home.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Have a look at the [Jenkins Job DSL Gradle example](https://github.com/sheehan/j
2222
* Added support for [Sonar Plugin](http://docs.sonarqube.org/display/SONAR/Jenkins+Plugin)
2323
* Added `recurse` option for list views
2424
* Added `ignorePostCommitHooks` option for SCM trigger
25+
* Added `commentFilePath` option for [GitHub Pull Request Builder Plugin](https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin)
2526
* Added "Configure Project" column for [Extra Columns Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Extra+Columns+Plugin)
2627
* Added support for [PostBuildScript Plugin](https://wiki.jenkins-ci.org/display/JENKINS/PostBuildScript+Plugin)
2728
* Added support for [Xvfb Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Xvfb+Plugin)

docs/Job-reference.md

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,23 +1366,29 @@ gerrit {
13661366
### Github Pull Request Trigger
13671367

13681368
```groovy
1369-
pullRequest {
1370-
admin(String admin) // add admin
1371-
admins(Iterable<String> admins) // add admins
1372-
userWhitelist(String user) // add user to whitelist
1373-
userWhitelist(Iterable<String> users) // add users to whitelist
1374-
orgWhitelist(String organization) // add organization to whitelist
1375-
orgWhitelist(Iterable<String> organizations) // add organizations to whitelist
1376-
cron(String cron) // set cron schedule, defaults to 'H/5 * * * *'
1377-
triggerPhrase(String triggerPhrase) // set phrase to trigger by commenting within the pull request
1378-
onlyTriggerPhrase(boolean onlyTriggerPhrase = true) // defaults to false if not specified
1379-
useGitHubHooks(boolean useGithubHooks = true) // defaults to false if not specified
1380-
permitAll(boolean permitAll = true) // defaults to false if not specified
1381-
autoCloseFailedPullRequests(boolean autoCloseFailedPullRequests = true) // defaults to false if not specified
1369+
job('example') {
1370+
triggers {
1371+
pullRequest {
1372+
admin(String admin)
1373+
admins(Iterable<String> admins)
1374+
userWhitelist(String user)
1375+
userWhitelist(Iterable<String> users)
1376+
orgWhitelist(String organization)
1377+
orgWhitelist(Iterable<String> organizations)
1378+
cron(String cron) // defaults to 'H/5 * * * *'
1379+
triggerPhrase(String triggerPhrase)
1380+
onlyTriggerPhrase(boolean value = true) // defaults to false
1381+
useGitHubHooks(boolean useGithubHooks = true) // defaults to false
1382+
permitAll(boolean permitAll = true) // defaults to false
1383+
autoCloseFailedPullRequests(boolean value = true) // defaults to false
1384+
commentFilePath(String commentFilePath) // since 1.31
1385+
}
1386+
}
13821387
}
13831388
```
13841389

1385-
Builds pull requests from GitHub and will report the results directly to the pull request. Requires the [GitHub pull request builder plugin](https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin). (Available since 1.22)
1390+
Builds pull requests from GitHub and will report the results directly to the pull request. Requires the
1391+
[GitHub pull request builder plugin](https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin).
13861392

13871393
The pull request builder plugin requires a special Git SCM configuration, see the plugin documentation for details.
13881394

@@ -1399,9 +1405,9 @@ job('example') {
13991405
}
14001406
triggers {
14011407
pullRequest {
1402-
admins('USER_ID')
1408+
admin('USER_ID')
14031409
userWhitelist('[email protected]')
1404-
orgWhitelist('your_github_org', 'another_org')
1410+
orgWhitelist(['your_github_org', 'another_org'])
14051411
cron('H/5 * * * *')
14061412
triggerPhrase('Ok to test')
14071413
onlyTriggerPhrase()
@@ -1413,6 +1419,8 @@ job('example') {
14131419
}
14141420
```
14151421

1422+
(since 1.22)
1423+
14161424
### URL Trigger
14171425

14181426
The URL trigger plugin checks one or more specified URLs and starts a build when a change is detected. (Since 1.16)

job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/triggers/PullRequestBuilderContext.groovy

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
package javaposse.jobdsl.dsl.helpers.triggers
22

33
import javaposse.jobdsl.dsl.Context
4+
import javaposse.jobdsl.dsl.JobManagement
45

56
class PullRequestBuilderContext implements Context {
7+
private final JobManagement jobManagement
8+
69
List admins = []
710
List userWhitelist = []
811
List orgWhitelist = []
912
String cron = 'H/5 * * * *'
10-
String triggerPhrase = ''
13+
String triggerPhrase
1114
boolean onlyTriggerPhrase = false
1215
boolean useGitHubHooks = false
1316
boolean permitAll = false
1417
boolean autoCloseFailedPullRequests = false
18+
String commentFilePath
19+
20+
PullRequestBuilderContext(JobManagement jobManagement) {
21+
this.jobManagement = jobManagement
22+
}
1523

1624
void admin(String admin) {
1725
admins << admin
@@ -47,6 +55,12 @@ class PullRequestBuilderContext implements Context {
4755
this.cron = cron
4856
}
4957

58+
void commentFilePath(String commentFilePath) {
59+
jobManagement.requireMinimumPluginVersion('ghprb', '1.14')
60+
61+
this.commentFilePath = commentFilePath
62+
}
63+
5064
void triggerPhrase(String triggerPhrase) {
5165
this.triggerPhrase = triggerPhrase
5266
}
@@ -66,5 +80,4 @@ class PullRequestBuilderContext implements Context {
6680
void autoCloseFailedPullRequests(boolean autoCloseFailedPullRequests = true) {
6781
this.autoCloseFailedPullRequests = autoCloseFailedPullRequests
6882
}
69-
7083
}

job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/triggers/TriggerContext.groovy

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,11 @@ class TriggerContext implements Context {
135135
* <useGitHubHooks>true</useGitHubHooks>
136136
* <permitAll>true</permitAll>
137137
* <autoCloseFailedPullRequests>false</autoCloseFailedPullRequests>
138+
* <commentFilePath>$WORKSPACE/myCommentFile.log</commentFilePath>
138139
* </org.jenkinsci.plugins.ghprb.GhprbTrigger>
139140
*/
140141
void pullRequest(@DslContext(PullRequestBuilderContext) Closure contextClosure) {
141-
PullRequestBuilderContext pullRequestBuilderContext = new PullRequestBuilderContext()
142+
PullRequestBuilderContext pullRequestBuilderContext = new PullRequestBuilderContext(jobManagement)
142143
ContextHelper.executeInContext(contextClosure, pullRequestBuilderContext)
143144

144145
triggerNodes << new NodeBuilder().'org.jenkinsci.plugins.ghprb.GhprbTrigger' {
@@ -147,11 +148,12 @@ class TriggerContext implements Context {
147148
orgslist pullRequestBuilderContext.orgWhitelist.join('\n')
148149
delegate.cron(pullRequestBuilderContext.cron)
149150
spec pullRequestBuilderContext.cron
150-
triggerPhrase pullRequestBuilderContext.triggerPhrase
151+
triggerPhrase pullRequestBuilderContext.triggerPhrase ?: ''
151152
onlyTriggerPhrase pullRequestBuilderContext.onlyTriggerPhrase
152153
useGitHubHooks pullRequestBuilderContext.useGitHubHooks
153154
permitAll pullRequestBuilderContext.permitAll
154155
autoCloseFailedPullRequests pullRequestBuilderContext.autoCloseFailedPullRequests
156+
commentFilePath pullRequestBuilderContext.commentFilePath ?: ''
155157
}
156158
}
157159

job-dsl-core/src/test/groovy/javaposse/jobdsl/dsl/helpers/triggers/TriggerContextSpec.groovy

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,8 @@ class TriggerContextSpec extends Specification {
300300

301301
def 'call pull request trigger with no args'() {
302302
when:
303-
context.pullRequest()
303+
context.pullRequest {
304+
}
304305

305306
then:
306307
def pullRequestNode = context.triggerNodes[0]
@@ -315,6 +316,7 @@ class TriggerContextSpec extends Specification {
315316
adminlist[0].value() == ''
316317
whitelist[0].value() == ''
317318
orgslist[0].value() == ''
319+
commentFilePath[0].value() == ''
318320
}
319321

320322
}
@@ -348,6 +350,7 @@ class TriggerContextSpec extends Specification {
348350
useGitHubHooks(true)
349351
permitAll(true)
350352
autoCloseFailedPullRequests(true)
353+
commentFilePath('myCommentFile')
351354
}
352355

353356
then:
@@ -364,7 +367,9 @@ class TriggerContextSpec extends Specification {
364367
useGitHubHooks[0].value() == true
365368
permitAll[0].value() == true
366369
autoCloseFailedPullRequests[0].value() == true
370+
commentFilePath[0].value() == 'myCommentFile'
367371
}
372+
1 * mockJobManagement.requireMinimumPluginVersion('ghprb', '1.14')
368373
}
369374

370375
def 'call empty gerrit trigger methods'() {

0 commit comments

Comments
 (0)