final String mvn = "mvn --batch-mode --update-snapshots" pipeline { agent any stages { 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('Static Code Analysis') { steps { withMaven(maven: 'maven-3.5.2', jdk: 'JDK 1.8') { sh "${mvn} 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 '**/target/*.jar' } } 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" } } } } }