Skip to content

Commit 576a042

Browse files
author
Blixt Daniel (Consultant)
committed
Add ability to review-build as multibranch pipeline
Addition of Jenkinsfile to enable pipeline build. Addition of multibranch pipeline job for reviews.
1 parent 78ed818 commit 576a042

File tree

2 files changed

+139
-0
lines changed

2 files changed

+139
-0
lines changed

Jenkinsfile

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!groovy
2+
/**
3+
* Pipeline configuration for JenkinsAsCode review-jobs
4+
*/
5+
6+
7+
/* global definitions */
8+
def integrationBranch = 'env.default_branch'
9+
10+
/**
11+
* begin pipeline
12+
*/
13+
14+
if (env.BRANCH_NAME == integrationBranch) {
15+
currentBuild.result = 'NOT_BUILT'
16+
return
17+
}
18+
19+
currentBuild.result = 'SUCCESS'
20+
try {
21+
node( env.utility_slave ) {
22+
ansiColor('xterm') {
23+
// execute tests using the job-dsl-plugin for private branches
24+
stage ( 'Checkout' ) {
25+
scm checkout
26+
}
27+
stage ( 'Build XML' ) {
28+
dir ('jobdsl-gradle') {
29+
sh script: '''
30+
./gradlew --no-daemon buildXMl
31+
'''.stripIndent().trim()
32+
}
33+
}
34+
stage ( 'test' ) {
35+
dir ('jobdsl-gradle') {
36+
sh script: '''
37+
./gradlew --no-daemon test
38+
'''.stripIndent().trim()
39+
}
40+
}
41+
42+
stage ( 'Build Docker' ) {
43+
dir ('dockerizeit') {
44+
sh script: '''
45+
# Assume no proxy if it is not set
46+
export http_proxy=${http_proxy:-}
47+
export https_proxy=${https_proxy:-}
48+
export no_proxy=${no_proxy:-}
49+
env
50+
docker-compose build
51+
'''.stripIndent().trim()
52+
}
53+
}
54+
55+
stage ( 'Generate compose yml' ) {
56+
dir ('dockerizeit') {
57+
sh script: '''
58+
./generate-compose.py \
59+
--debug \
60+
--file docker-compose.yml \
61+
--jmaster-image test-image \
62+
--jmaster-version test-version \
63+
--jslave-image test-image \
64+
--jslave-version test-version \
65+
&& cat docker-compose.yml \
66+
&& git checkout HEAD docker-compose.yml
67+
'''.stripIndent().trim()
68+
}
69+
}
70+
stage ( 'Build Munchausen' ) {
71+
dir ('dockerizeit/munchausen') {
72+
sh script: '''
73+
cp ../docker-compose.yml .
74+
docker build \
75+
--build-arg http_proxy \
76+
--build-arg https_proxy \
77+
--build-arg no_proxy \
78+
-t munchausen \
79+
.
80+
'''.stripIndent().trim()
81+
}
82+
}
83+
}
84+
}
85+
} catch ( e ) {
86+
currentBuild.result = 'FAILURE'
87+
throw e
88+
}
89+
finally {
90+
println ( "done" )
91+
}
92+
/**
93+
* end pipeline
94+
*/
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import javaposse.jobdsl.dsl.DslFactory
2+
import javaposse.jobdsl.dsl.Job
3+
4+
def defaultCredentials = Helpers.readEnvVariable("default_credentials", "")
5+
def defaultBranch = Helpers.readEnvVariable("default_branch", "")
6+
def defaultRepo = Helpers.readEnvVariable("default_repo", "")
7+
8+
DslFactory dslFactory = this
9+
dslFactory.multibranchPipelineJob( "jenkins_as_a_code-review-pipeline" ) {
10+
11+
branchSources {
12+
github {
13+
buildOriginBranchWithPR ( false )
14+
buildOriginPRMerge ( true )
15+
checkoutCredentialsId ( defaultCredentials )
16+
// Exclude default branch from review builds - that one will be built by jenkins_as_a_code-pipeline instead.
17+
if ( defaultBranch != "" ) {
18+
excludes ( defaultBranch )
19+
}
20+
repoTokens = defaultRepo.split(':')[-1].split('/')
21+
if (repoTokens.length > 2) {
22+
repoName = '/'.join(repoTokens[1..-1])
23+
repoOwner( ${repoTokens[0]}
24+
} else if (repoTokens.length == 2 ) {
25+
repoName = repoTokens[1]
26+
repoOwner( ${repoTokens[0]}
27+
} else {
28+
repoName = repoTokens[0]
29+
}
30+
repository ( repoName )
31+
scanCredentialsId ( "" )
32+
}
33+
34+
triggers {
35+
periodic ( 240 )
36+
}
37+
38+
// remove dead branches and logs
39+
orphanedItemStrategy {
40+
discardOldItems {
41+
numToKeep( 0 )
42+
daysToKeep( 1 )
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)