Merge branch 'jenkins' into 'master'

Rewrite Jenkinsfile for resource only project with trunk-style branching model

See merge request kemitix/kemitix-pmd-ruleset!8
This commit is contained in:
Paul Campbell 2018-07-03 06:35:04 +00:00
commit 37a440e683

View file

@ -1,39 +1,67 @@
final String mvn = "mvn --batch-mode --update-snapshots"
final String mvn = "mvn --batch-mode --update-snapshots --errors"
final Integer dependenciesSupportJDK = 10
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
stage('release != SNAPSHOT') {
// checks that the pom version is not a SNAPSHOT when the current branch is a release
when {
expression {
(env.GIT_BRANCH == 'master') &&
(readMavenPom(file: 'pom.xml').version).contains("SNAPSHOT") }
(branchStartsWith('release/')) &&
(readMavenPom(file: 'pom.xml').version).contains("SNAPSHOT")
}
}
steps {
error("Build failed because SNAPSHOT version")
error("Build failed because SNAPSHOT version: [" + env.GIT_BRANCH + "]")
}
}
stage('Build') {
stage('Install') {
steps {
withMaven(maven: 'maven 3.5.2', jdk: 'JDK 9') {
sh 'mvn clean install'
withMaven(maven: 'maven', jdk: 'JDK 1.8') {
sh "${mvn} -DskipTests install"
}
}
}
stage('Archiving') {
stage('Deploy (release on gitlab)') {
when {
expression {
(branchStartsWith('release/') && isPublished())
}
}
steps {
archiveArtifacts '**/classes/**/*.xml'
withMaven(maven: 'maven', jdk: 'JDK 1.8') {
sh "${mvn} --activate-profiles release deploy"
}
}
stage('Deploy') {
when { expression { (env.GIT_BRANCH == 'master') } }
}
stage('Build Java 9') {
when { expression { dependenciesSupportJDK >= 9 } }
steps {
withMaven(maven: 'maven 3.5.2', jdk: 'JDK 1.8') {
sh "${mvn} deploy --activate-profiles release -DskipTests=true"
withMaven(maven: 'maven', jdk: 'JDK 9') {
sh "${mvn} clean verify -Djava.version=9"
}
}
}
stage('Build Java 10') {
when { expression { dependenciesSupportJDK >= 10 } }
steps {
withMaven(maven: 'maven', jdk: 'JDK 10') {
sh "${mvn} clean verify -Djava.version=10"
}
}
}
}
}
private boolean branchStartsWith(String branchName) {
startsWith(env.GIT_BRANCH, branchName)
}
private boolean isPublished() {
startsWith(env.GIT_URL, 'https://')
}
private boolean startsWith(String value, String match) {
value != null && value.startsWith(match)
}