diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..c86dec4 --- /dev/null +++ b/Jenkinsfile @@ -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 +*/ diff --git a/jobdsl-gradle/src/jobs/groovy/review_mb_pipeline.groovy b/jobdsl-gradle/src/jobs/groovy/review_mb_pipeline.groovy new file mode 100644 index 0000000..baf69e5 --- /dev/null +++ b/jobdsl-gradle/src/jobs/groovy/review_mb_pipeline.groovy @@ -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 ) + } + } +}