diff --git a/Jenkinsfile.groovy b/Jenkinsfile.groovy index e61c0ee..6ffc2a3 100644 --- a/Jenkinsfile.groovy +++ b/Jenkinsfile.groovy @@ -1,21 +1,9 @@ +final String publicRepo = 'https://github.com/kemitix/' final String mvn = "mvn --batch-mode --update-snapshots --errors" -final Integer dependenciesSupportJDK = 10 pipeline { agent any stages { - stage('release != SNAPSHOT') { - // checks that the pom version is not a SNAPSHOT when the current branch is a release - when { - expression { - (branchStartsWith('release/')) && - (readMavenPom(file: 'pom.xml').version).contains("SNAPSHOT") - } - } - steps { - error("Build failed because SNAPSHOT version: [" + env.GIT_BRANCH + "]") - } - } stage('Install') { steps { withMaven(maven: 'maven', jdk: 'JDK 1.8') { @@ -23,10 +11,12 @@ pipeline { } } } - stage('Deploy (release on gitlab)') { + stage('Deploy (published release branch)') { when { expression { - (branchStartsWith('release/') && isPublished()) + (isReleaseBranch() && + isPublished(publicRepo) && + notSnapshot()) } } steps { @@ -35,33 +25,25 @@ pipeline { } } } - stage('Build Java 9') { - when { expression { dependenciesSupportJDK >= 9 } } - steps { - 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) { +private boolean isReleaseBranch() { + return branchStartsWith('release/') +} + +private boolean branchStartsWith(final String branchName) { startsWith(env.GIT_BRANCH, branchName) } -private boolean isPublished() { - startsWith(env.GIT_URL, 'https://') +private boolean isPublished(final String repo) { + startsWith(env.GIT_URL, repo) } -private boolean startsWith(String value, String match) { +private static boolean startsWith(final String value, final String match) { value != null && value.startsWith(match) } + +private boolean notSnapshot() { + return !(readMavenPom(file: 'pom.xml').version).contains("SNAPSHOT") +}