Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to review-build as multibranch pipeline #216

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!groovy
/**
* Pipeline configuration for JenkinsAsCode review-jobs
*/


/* global definitions */
def integrationBranch = 'env.default_branch'

/**
* begin pipeline
*/

if (env.BRANCH_NAME == integrationBranch) {
currentBuild.result = 'NOT_BUILT'
return
}

currentBuild.result = 'SUCCESS'
try {
node( env.utility_slave ) {
ansiColor('xterm') {
// execute tests using the job-dsl-plugin for private branches
stage ( 'Checkout' ) {
scm checkout
}
stage ( 'Build XML' ) {
dir ('jobdsl-gradle') {
sh script: '''
./gradlew --no-daemon buildXMl
'''.stripIndent().trim()
}
}
stage ( 'test' ) {
dir ('jobdsl-gradle') {
sh script: '''
./gradlew --no-daemon test
'''.stripIndent().trim()
}
}
stage ( 'Build Docker' ) {
dir ('dockerizeit') {
sh script: '''
# Assume no proxy if it is not set
export http_proxy=${http_proxy:-}
export https_proxy=${https_proxy:-}
export no_proxy=${no_proxy:-}
env
docker-compose build
'''.stripIndent().trim()
}
}
stage ( 'Generate compose yml' ) {
dir ('dockerizeit') {
sh script: '''
./generate-compose.py \
--debug \
--file docker-compose.yml \
--jmaster-image test-image \
--jmaster-version test-version \
--jslave-image test-image \
--jslave-version test-version \
&& cat docker-compose.yml \
&& git checkout HEAD docker-compose.yml
'''.stripIndent().trim()
}
}
stage ( 'Build Munchausen' ) {
dir ('dockerizeit/munchausen') {
sh script: '''
cp ../docker-compose.yml .
docker build \
--build-arg http_proxy \
--build-arg https_proxy \
--build-arg no_proxy \
-t munchausen \
.
'''.stripIndent().trim()
}
}
}
}
} catch ( e ) {
currentBuild.result = 'FAILURE'
throw e
}
finally {
println ( "done" )
}
/**
* end pipeline
*/
51 changes: 51 additions & 0 deletions jobdsl-gradle/src/jobs/groovy/review_mb_pipeline.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import job.Helpers

import javaposse.jobdsl.dsl.DslFactory
import javaposse.jobdsl.dsl.Job

def defaultCredentials = Helpers.readEnvVariable("default_credentials", "")
def defaultBranch = Helpers.readEnvVariable("default_branch", "")
def defaultRepo = Helpers.readEnvVariable("default_repo", "")

DslFactory dslFactory = this
dslFactory.multibranchPipelineJob( "jenkins_as_a_code-review-pipeline" ) {

branchSources {
github {
buildOriginBranchWithPR ( false )
buildOriginPRMerge ( true )
checkoutCredentialsId ( defaultCredentials )
// Exclude default branch from review builds - that one will be built by jenkins_as_a_code-pipeline instead.
if ( defaultBranch != "" ) {
excludes ( defaultBranch )
}
// Parse out repository and organisation from default_repo
repoTokens = defaultRepo.split(':')[-1].split('/')
if (repoTokens.length > 2) {
repoName = '/'.join(repoTokens[1..-1])
repoOwner( ${repoTokens[0]} )
} else if (repoTokens.length == 2 ) {
repoName = repoTokens[1]
repoOwner( ${repoTokens[0]} )
} else {
repoName = repoTokens[0]
}
repository ( repoName )

scanCredentialsId ( "" )
}
}

triggers {
// Scan MB-pipeline every 4hours.
periodic ( 240 )
}

// remove dead branches and logs
orphanedItemStrategy {
discardOldItems {
numToKeep( 0 )
daysToKeep( 1 )
}
}
}