kemitix-checkstyle-ruleset/Jenkinsfile.groovy

84 lines
3.3 KiB
Groovy
Raw Normal View History

2018-05-14 18:55:04 +01:00
final String mvn = "mvn --batch-mode --update-snapshots --errors"
2018-03-09 19:53:26 +00:00
pipeline {
agent any
stages {
2018-04-18 20:24:31 +01:00
stage('master != SNAPSHOT') {
2018-03-09 19:53:26 +00:00
// checks that the pom version is not a snapshot when the current or target branch is master
when {
expression {
(env.GIT_BRANCH == 'master' || env.CHANGE_TARGET == 'master') &&
(readMavenPom(file: 'pom.xml').version).contains("SNAPSHOT")
}
}
steps {
error("Build failed because SNAPSHOT version")
}
}
2018-04-18 20:24:31 +01:00
stage('Build & Test') {
2018-03-09 19:53:26 +00:00
steps {
2018-03-10 18:41:07 +00:00
withMaven(maven: 'maven', jdk: 'JDK LTS') {
2018-04-18 20:24:31 +01:00
sh "${mvn} clean compile checkstyle:checkstyle pmd:pmd test"
//junit '**/target/surefire-reports/*.xml'
sh "${mvn} -pl builder jacoco:report 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`"
jacoco exclusionPattern: '**/*{Test|IT|Main|Application|Immutable}.class'
2018-03-10 18:41:07 +00:00
pmd canComputeNew: false, defaultEncoding: '', healthy: '', pattern: '', unHealthy: ''
2018-04-18 20:24:31 +01:00
step([$class: 'hudson.plugins.checkstyle.CheckStylePublisher',
pattern: '**/target/checkstyle-result.xml',
healthy:'20',
unHealthy:'100'])
}
}
}
2018-04-18 20:24:31 +01:00
stage('Verify & Install') {
2018-03-09 19:53:26 +00:00
steps {
2018-03-10 18:41:07 +00:00
withMaven(maven: 'maven', jdk: 'JDK LTS') {
2018-04-18 20:24:31 +01:00
sh "${mvn} -DskipTests install"
2018-03-09 19:53:26 +00:00
}
}
}
2018-04-18 20:24:31 +01:00
stage('SonarQube (github only)') {
when { expression { env.GIT_URL.startsWith('https://github.com') } }
2018-03-09 19:53:26 +00:00
steps {
2018-04-18 20:24:31 +01:00
withSonarQubeEnv('sonarqube') {
withMaven(maven: 'maven', jdk: 'JDK LTS') {
sh "${mvn} org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.0.905:sonar"
}
2018-03-09 19:53:26 +00:00
}
}
}
stage('Archiving') {
when { expression { findFiles(glob: '**/target/*.jar').length > 0 } }
steps {
archiveArtifacts '**/target/*.jar'
}
}
2018-04-18 20:24:31 +01:00
stage('Deploy (master on github)') {
when { expression { (env.GIT_BRANCH == 'master' && env.GIT_URL.startsWith('https://github.com')) } }
2018-03-09 19:53:26 +00:00
steps {
2018-03-10 18:41:07 +00:00
withMaven(maven: 'maven', jdk: 'JDK LTS') {
2018-04-18 20:24:31 +01:00
sh "${mvn} deploy --activate-profiles release -DskipTests=true"
}
}
}
stage('Build Java 9') {
steps {
withMaven(maven: 'maven', jdk: 'JDK 9') {
sh "${mvn} clean verify -Djava.version=9"
2018-03-09 19:53:26 +00:00
}
}
}
2018-05-14 18:55:26 +01:00
stage('Build Java 10') {
steps {
withMaven(maven: 'maven', jdk: 'JDK 10') {
sh "${mvn} clean verify -Djava.version=10"
}
}
}
2018-03-09 19:53:26 +00:00
}
}