From d646a98dbc72c7245aa9b6a50f11b4687944680f Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Wed, 28 Feb 2018 17:08:05 +0000 Subject: [PATCH 01/10] version set to 5.2.0-SNAPSHOT --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c06ec1b..5c0eb3f 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ net.kemitix kemitix-parent - 5.1.0 + 5.2.0-SNAPSHOT pom Kemitix Parent From b5f13e0038ef171eacf45ea465bd6c750c1a6000 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Wed, 28 Feb 2018 18:35:09 +0000 Subject: [PATCH 02/10] Update set-version to better detect current version --- set-version.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/set-version.sh b/set-version.sh index 61099c3..f882f33 100644 --- a/set-version.sh +++ b/set-version.sh @@ -1,15 +1,19 @@ #!/usr/bin/env bash +cd `dirname $0` +PROJECT=`basename $PWD` + if test $# != 1 then echo "next version missing" exit fi -CURRENT=`grep '' pom.xml |head -n 1| sed 's/.*>\(.*\)<.*/\1/'` +CURRENT=`grep -C 2 "${PROJECT}" pom.xml | grep '' | sed 's/.*>\(.*\)<.*/\1/'` NEXT=$1 echo Updating version from $CURRENT to $NEXT ./mvnw versions:set -DnewVersion=$NEXT -perl -p -i -e "s,$CURRENT Date: Sun, 4 Mar 2018 17:37:23 +0000 Subject: [PATCH 03/10] jenkins: update to latest template --- Jenkinsfile | 28 ----------------------- Jenkinsfile.groovy | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 28 deletions(-) delete mode 100644 Jenkinsfile create mode 100644 Jenkinsfile.groovy diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index 4e84469..0000000 --- a/Jenkinsfile +++ /dev/null @@ -1,28 +0,0 @@ -final String gitRepoUrl = 'git@github.com:kemitix/kemitix-parent.git' -final String mvn = "mvn --batch-mode --update-snapshots" - -pipeline { - agent any - stages { - stage('Prepare') { - steps { - git url: gitRepoUrl, branch: '**', credentialsId: 'github-kemitix' - } - } - stage('Build') { - steps { - withMaven(maven: 'maven 3.5.2', jdk: 'JDK 1.8') { - sh "${mvn} clean install" - } - } - } - stage('Deploy') { - when { expression { (env.GIT_BRANCH == 'master') } } - steps { - withMaven(maven: 'maven 3.5.2', jdk: 'JDK 1.8') { - sh "${mvn} deploy --activate-profiles release" - } - } - } - } -} diff --git a/Jenkinsfile.groovy b/Jenkinsfile.groovy new file mode 100644 index 0000000..0e18978 --- /dev/null +++ b/Jenkinsfile.groovy @@ -0,0 +1,57 @@ +final String repoName = "kemitix-parent" +final String repoUrl = "git@github.com:kemitix/${repoName}.git" +final String mvn = "mvn --batch-mode --update-snapshots" + +pipeline { + agent any + stages { + stage('Prepare') { + steps { + git url: repoUrl, branch: '**', credentialsId: 'github-kemitix' + } + } + stage('no SNAPSHOT in master') { + // checks that the pom version is not a snapshot when the current branch is master + // TODO: also check for SNAPSHOT when is a pull request with master as the target branch + when { + expression { + (env.GIT_BRANCH == 'master') && + (readMavenPom(file: 'pom.xml').version).contains("SNAPSHOT") } + } + steps { + error("Build failed because SNAPSHOT version") + } + } + stage('Build') { + parallel { + stage('Java 8') { + steps { + withMaven(maven: 'maven 3.5.2', jdk: 'JDK 1.8') { + sh "${mvn} clean install" + } + } + } + stage('Java 9') { + steps { + withMaven(maven: 'maven 3.5.2', jdk: 'JDK 9') { + sh 'mvn clean install' + } + } + } + } + } + stage('Archiving') { + steps { + archiveArtifacts 'pom.xml' + } + } + stage('Deploy') { + when { expression { (env.GIT_BRANCH == 'master') } } + steps { + withMaven(maven: 'maven 3.5.2', jdk: 'JDK 1.8') { + sh "${mvn} deploy --activate-profiles release -DskipTests=true" + } + } + } + } +} From 5e28fbb65dfc2564ebeb8c5c5e3ca03af61e9a42 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sun, 4 Mar 2018 17:50:56 +0000 Subject: [PATCH 04/10] jenkins: build and deploy using Java 9 --- Jenkinsfile.groovy | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/Jenkinsfile.groovy b/Jenkinsfile.groovy index 0e18978..68be5c8 100644 --- a/Jenkinsfile.groovy +++ b/Jenkinsfile.groovy @@ -23,20 +23,9 @@ pipeline { } } stage('Build') { - parallel { - stage('Java 8') { - steps { - withMaven(maven: 'maven 3.5.2', jdk: 'JDK 1.8') { - sh "${mvn} clean install" - } - } - } - stage('Java 9') { - steps { - withMaven(maven: 'maven 3.5.2', jdk: 'JDK 9') { - sh 'mvn clean install' - } - } + steps { + withMaven(maven: 'maven 3.5.2', jdk: 'JDK 9') { + sh 'mvn clean install' } } } @@ -48,7 +37,7 @@ pipeline { stage('Deploy') { when { expression { (env.GIT_BRANCH == 'master') } } steps { - withMaven(maven: 'maven 3.5.2', jdk: 'JDK 1.8') { + withMaven(maven: 'maven 3.5.2', jdk: 'JDK 9') { sh "${mvn} deploy --activate-profiles release -DskipTests=true" } } From af91570c01096cd7b709291e447ad7a9259fe7a9 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sun, 4 Mar 2018 18:06:12 +0000 Subject: [PATCH 05/10] lombok.config: added to prevent generated annotation --- lombok.config | 1 + 1 file changed, 1 insertion(+) create mode 100644 lombok.config diff --git a/lombok.config b/lombok.config new file mode 100644 index 0000000..00ebb3e --- /dev/null +++ b/lombok.config @@ -0,0 +1 @@ +lombok.addGeneratedAnnotation=false From 56862fadd6601796c240dfa2abf14a1ce8bfdb8b Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 6 Mar 2018 17:22:05 +0000 Subject: [PATCH 06/10] jenkins: Remove redundant Prepare stage --- Jenkinsfile.groovy | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Jenkinsfile.groovy b/Jenkinsfile.groovy index 68be5c8..ea81f66 100644 --- a/Jenkinsfile.groovy +++ b/Jenkinsfile.groovy @@ -1,15 +1,8 @@ -final String repoName = "kemitix-parent" -final String repoUrl = "git@github.com:kemitix/${repoName}.git" final String mvn = "mvn --batch-mode --update-snapshots" pipeline { agent any stages { - stage('Prepare') { - steps { - git url: repoUrl, branch: '**', credentialsId: 'github-kemitix' - } - } stage('no SNAPSHOT in master') { // checks that the pom version is not a snapshot when the current branch is master // TODO: also check for SNAPSHOT when is a pull request with master as the target branch From a377a3b50890ecc3a942d3743438b67eb488dc72 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Thu, 8 Mar 2018 22:26:31 +0000 Subject: [PATCH 07/10] jenkins: report environment, no snapshots in PRs to master and only deploy from https repos --- Jenkinsfile.groovy | 54 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/Jenkinsfile.groovy b/Jenkinsfile.groovy index ea81f66..02c109f 100644 --- a/Jenkinsfile.groovy +++ b/Jenkinsfile.groovy @@ -3,34 +3,70 @@ final String mvn = "mvn --batch-mode --update-snapshots" pipeline { agent any stages { + stage('Environment') { + steps { + sh 'set' + } + } stage('no SNAPSHOT in master') { - // checks that the pom version is not a snapshot when the current branch is master - // TODO: also check for SNAPSHOT when is a pull request with master as the target branch + // checks that the pom version is not a snapshot when the current or target branch is master when { expression { - (env.GIT_BRANCH == 'master') && + (env.GIT_BRANCH == 'master' || env.CHANGE_TARGET == 'master') && (readMavenPom(file: 'pom.xml').version).contains("SNAPSHOT") } } steps { error("Build failed because SNAPSHOT version") } } - stage('Build') { + stage('Static Code Analysis') { steps { - withMaven(maven: 'maven 3.5.2', jdk: 'JDK 9') { - sh 'mvn clean install' + withMaven(maven: 'maven 3.5.2', jdk: 'JDK 1.8') { + sh "${mvn} compile checkstyle:checkstyle pmd:pmd" + } + pmd canComputeNew: false, defaultEncoding: '', healthy: '', pattern: '', unHealthy: '' + } + } + stage('Build') { + parallel { + stage('Java 8') { + steps { + withMaven(maven: 'maven 3.5.2', jdk: 'JDK 1.8') { + sh "${mvn} clean install" + } + } + } + stage('Java 9') { + steps { + withMaven(maven: 'maven 3.5.2', jdk: 'JDK 9') { + sh "${mvn} clean install" + } + } + } + } + } + stage('Test Results') { + steps { + junit '**/target/surefire-reports/*.xml' + jacoco exclusionPattern: '**/*{Test|IT|Main|Application|Immutable}.class' + withMaven(maven: 'maven 3.5.2', jdk: 'JDK 1.8') { + sh "${mvn} com.gavinmogan:codacy-maven-plugin:coverage " + + "-DcoverageReportFile=target/site/jacoco/jacoco.xml " + + "-DprojectToken=`$JENKINS_HOME/codacy/token` " + + "-DapiToken=`$JENKINS_HOME/codacy/apitoken` " + + "-Dcommit=`git rev-parse HEAD`" } } } stage('Archiving') { steps { - archiveArtifacts 'pom.xml' + archiveArtifacts '**/target/*.jar' } } stage('Deploy') { - when { expression { (env.GIT_BRANCH == 'master') } } + when { expression { (env.GIT_BRANCH == 'master' && env.GIT_URL.startsWith('https://')) } } steps { - withMaven(maven: 'maven 3.5.2', jdk: 'JDK 9') { + withMaven(maven: 'maven 3.5.2', jdk: 'JDK 1.8') { sh "${mvn} deploy --activate-profiles release -DskipTests=true" } } From 1cc7246d85e2f547112d538873d87c701594827d Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 9 Mar 2018 17:30:59 +0000 Subject: [PATCH 08/10] jenkins: only enter some stages when suitable files exist --- Jenkinsfile.groovy | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Jenkinsfile.groovy b/Jenkinsfile.groovy index 02c109f..8516706 100644 --- a/Jenkinsfile.groovy +++ b/Jenkinsfile.groovy @@ -20,6 +20,7 @@ pipeline { } } stage('Static Code Analysis') { + when { expression { findFiles(glob: '**/src/main/java/*.java').length > 0 } } steps { withMaven(maven: 'maven 3.5.2', jdk: 'JDK 1.8') { sh "${mvn} compile checkstyle:checkstyle pmd:pmd" @@ -46,6 +47,7 @@ pipeline { } } stage('Test Results') { + when { expression { findFiles(glob: '**/target/surefire-reports/*.xml').length > 0 } } steps { junit '**/target/surefire-reports/*.xml' jacoco exclusionPattern: '**/*{Test|IT|Main|Application|Immutable}.class' @@ -59,6 +61,7 @@ pipeline { } } stage('Archiving') { + when { expression { findFiles(glob: '**/target/*.jar').length > 0 } } steps { archiveArtifacts '**/target/*.jar' } From ab2873d221d4de92789d678f22bef95fefe0ebfc Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 9 Mar 2018 19:34:24 +0000 Subject: [PATCH 09/10] jenkins: don't run builds in parallel --- Jenkinsfile.groovy | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/Jenkinsfile.groovy b/Jenkinsfile.groovy index 8516706..9a099d9 100644 --- a/Jenkinsfile.groovy +++ b/Jenkinsfile.groovy @@ -13,7 +13,8 @@ pipeline { when { expression { (env.GIT_BRANCH == 'master' || env.CHANGE_TARGET == 'master') && - (readMavenPom(file: 'pom.xml').version).contains("SNAPSHOT") } + (readMavenPom(file: 'pom.xml').version).contains("SNAPSHOT") + } } steps { error("Build failed because SNAPSHOT version") @@ -28,21 +29,17 @@ pipeline { pmd canComputeNew: false, defaultEncoding: '', healthy: '', pattern: '', unHealthy: '' } } - stage('Build') { - parallel { - stage('Java 8') { - steps { - withMaven(maven: 'maven 3.5.2', jdk: 'JDK 1.8') { - sh "${mvn} clean install" - } - } + stage('Build Java 8') { + steps { + withMaven(maven: 'maven 3.5.2', jdk: 'JDK 1.8') { + sh "${mvn} clean install" } - stage('Java 9') { - steps { - withMaven(maven: 'maven 3.5.2', jdk: 'JDK 9') { - sh "${mvn} clean install" - } - } + } + } + stage('Build Java 9') { + steps { + withMaven(maven: 'maven 3.5.2', jdk: 'JDK 9') { + sh "${mvn} clean install" } } } From b622d7ea59a3fe5a455132b22b32d3c3f9da8f08 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 9 Mar 2018 22:36:19 +0000 Subject: [PATCH 10/10] jenkins: buid with java 9 first for test, then install with 8 --- Jenkinsfile.groovy | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile.groovy b/Jenkinsfile.groovy index 9a099d9..268e49c 100644 --- a/Jenkinsfile.groovy +++ b/Jenkinsfile.groovy @@ -29,16 +29,16 @@ pipeline { pmd canComputeNew: false, defaultEncoding: '', healthy: '', pattern: '', unHealthy: '' } } - stage('Build Java 8') { + stage('Build Java 9') { steps { - withMaven(maven: 'maven 3.5.2', jdk: 'JDK 1.8') { + withMaven(maven: 'maven 3.5.2', jdk: 'JDK 9') { sh "${mvn} clean install" } } } - stage('Build Java 9') { + stage('Build Java 8') { steps { - withMaven(maven: 'maven 3.5.2', jdk: 'JDK 9') { + withMaven(maven: 'maven 3.5.2', jdk: 'JDK 1.8') { sh "${mvn} clean install" } }