Skip to content

Commit 350005c

Browse files
authored
Merge pull request #1187 from daspilker/JENKINS-43693
[JENKINS-43693] improve multi-branch pipeline support
2 parents 88456f9 + afcc686 commit 350005c

File tree

12 files changed

+75
-7
lines changed

12 files changed

+75
-7
lines changed

docs/Home.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ Browse the Jenkins issue tracker to see any [open issues](https://issues.jenkins
3333

3434
## Release Notes
3535
* 1.75 (unreleased)
36+
* Added documentation about mandatory identifier in multi-branch Pipeline job branch sources, the identifier will no
37+
longer be generated and must be set to a constant and unique value, see [Migration](Migration#migrating-to-175)
38+
([JENKINS-43693](https://issues.jenkins-ci.org/browse/JENKINS-43693))
3639
* Enhanced support for the [Branch API Plugin](https://plugins.jenkins.io/branch-api)
3740
([JENKINS-54877](https://issues.jenkins-ci.org/browse/JENKINS-54877))
3841
* Fixed [[Dynamic DSL]] problem

docs/Migration.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
## Migrating to 1.75
2+
3+
The `id` option in the Git and GitHub branch source contexts is now mandatory
4+
([JENKINS-43693](https://issues.jenkins-ci.org/browse/JENKINS-43693)).
5+
6+
DSL prior to 1.75
7+
```groovy
8+
multibranchPipelineJob('example') {
9+
branchSources {
10+
github {
11+
}
12+
}
13+
}
14+
```
15+
16+
DSL since 1.75
17+
```groovy
18+
multibranchPipelineJob('example') {
19+
branchSources {
20+
github {
21+
id('12312313') // IMPORTANT: use a constant and unique identifier
22+
}
23+
}
24+
}
25+
```
26+
127
## Migrating to 1.72
228

329
### CloudBees Folders Plugin

job-dsl-core/src/main/docs/examples/javaposse/jobdsl/dsl/DslFactory/multibranchPipelineJob.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
multibranchPipelineJob('example') {
22
branchSources {
33
git {
4+
id('123456789') // IMPORTANT: use a constant and unique identifier
45
remote('https://github.com/jenkinsci/job-dsl-plugin.git')
56
credentialsId('github-ci')
67
includes('JENKINS-*')

job-dsl-core/src/main/docs/examples/javaposse/jobdsl/dsl/helpers/workflow/BranchSourcesContext/git.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
multibranchPipelineJob('example') {
22
branchSources {
33
git {
4+
id('12121212') // IMPORTANT: use a constant and unique identifier
45
remote('https://github.com/jenkinsci/job-dsl-plugin.git')
56
credentialsId('github-ci')
67
includes('JENKINS-*')

job-dsl-core/src/main/docs/examples/javaposse/jobdsl/dsl/helpers/workflow/BranchSourcesContext/github.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
multibranchPipelineJob('example') {
22
branchSources {
33
github {
4+
id('23232323') // IMPORTANT: use a constant and unique identifier
45
scanCredentialsId('github-ci')
56
repoOwner('OwnerName')
67
repository('job-dsl-plugin')

job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/DslFactory.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ interface DslFactory extends ViewFactory {
130130
/**
131131
* Create or updates a multibranch pipeline job.
132132
*
133+
* <b>IMPORTANT</b>: Make sure that each branch source has a constant and unique identifier.
134+
*
133135
* @since 1.47
134136
* @see #multibranchPipelineJob(java.lang.String, groovy.lang.Closure)
135137
*/
@@ -156,6 +158,8 @@ interface DslFactory extends ViewFactory {
156158
/**
157159
* Creates or updates a multibranch pipeline job.
158160
*
161+
* <b>IMPORTANT</b>: Make sure that each branch source has a constant and unique identifier.
162+
*
159163
* @since 1.47
160164
*/
161165
@RequiresPlugin(id = 'workflow-multibranch', minimumVersion = '2.10', failIfMissing = true)

job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/workflow/BranchSourcesContext.groovy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import javaposse.jobdsl.dsl.ContextType
66
import javaposse.jobdsl.dsl.DslContext
77
import javaposse.jobdsl.dsl.Item
88
import javaposse.jobdsl.dsl.JobManagement
9+
import javaposse.jobdsl.dsl.Preconditions
910
import javaposse.jobdsl.dsl.RequiresPlugin
1011

1112
@ContextType('jenkins.branch.BranchSource')
@@ -24,6 +25,8 @@ class BranchSourcesContext extends AbstractExtensibleContext {
2425
GitBranchSourceContext context = new GitBranchSourceContext()
2526
ContextHelper.executeInContext(branchSourceClosure, context)
2627

28+
Preconditions.checkNotNullOrEmpty(context.id, 'id must be specified')
29+
2730
branchSourceNodes << new NodeBuilder().'jenkins.branch.BranchSource' {
2831
source(class: 'jenkins.plugins.git.GitSCMSource') {
2932
id(context.id)
@@ -49,6 +52,8 @@ class BranchSourcesContext extends AbstractExtensibleContext {
4952
GitHubBranchSourceContext context = new GitHubBranchSourceContext(jobManagement)
5053
ContextHelper.executeInContext(branchSourceClosure, context)
5154

55+
Preconditions.checkNotNullOrEmpty(context.id, 'id must be specified')
56+
5257
branchSourceNodes << new NodeBuilder().'jenkins.branch.BranchSource' {
5358
source(class: 'org.jenkinsci.plugins.github_branch_source.GitHubSCMSource') {
5459
id(context.id)

job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/workflow/GitBranchSourceContext.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package javaposse.jobdsl.dsl.helpers.workflow
33
import javaposse.jobdsl.dsl.Context
44

55
class GitBranchSourceContext implements Context {
6-
String id = UUID.randomUUID()
6+
String id
77
String remote
88
String credentialsId
99
String includes = '*'

job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/workflow/GitHubBranchSourceContext.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import javaposse.jobdsl.dsl.AbstractContext
44
import javaposse.jobdsl.dsl.JobManagement
55

66
class GitHubBranchSourceContext extends AbstractContext {
7-
String id = UUID.randomUUID()
7+
String id
88
String apiUri
99
String scanCredentialsId
1010
String checkoutCredentialsId = 'SAME'

job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/jobs/MultibranchWorkflowJob.groovy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class MultibranchWorkflowJob extends ComputedFolder {
1414

1515
/**
1616
* Adds branch sources.
17+
*
18+
* <b>IMPORTANT</b>: Make sure that each branch source has a constant and unique identifier.
1719
*/
1820
void branchSources(@DslContext(BranchSourcesContext) Closure sourcesClosure) {
1921
BranchSourcesContext context = new BranchSourcesContext(jobManagement, this)

0 commit comments

Comments
 (0)