jenkins: report environment, no snapshots in PRs to master and only deploy from https repos

This commit is contained in:
Paul Campbell 2018-03-08 22:26:31 +00:00
parent 1f35e96e20
commit a377a3b508

View file

@ -3,34 +3,70 @@ final String mvn = "mvn --batch-mode --update-snapshots"
pipeline { pipeline {
agent any agent any
stages { stages {
stage('Environment') {
steps {
sh 'set'
}
}
stage('no SNAPSHOT in master') { stage('no SNAPSHOT in master') {
// checks that the pom version is not a snapshot when the current branch is master // checks that the pom version is not a snapshot when the current or target branch is master
// TODO: also check for SNAPSHOT when is a pull request with master as the target branch
when { when {
expression { expression {
(env.GIT_BRANCH == 'master') && (env.GIT_BRANCH == 'master' || env.CHANGE_TARGET == 'master') &&
(readMavenPom(file: 'pom.xml').version).contains("SNAPSHOT") } (readMavenPom(file: 'pom.xml').version).contains("SNAPSHOT") }
} }
steps { steps {
error("Build failed because SNAPSHOT version") error("Build failed because SNAPSHOT version")
} }
} }
stage('Static Code Analysis') {
steps {
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') { 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 { steps {
withMaven(maven: 'maven 3.5.2', jdk: 'JDK 9') { withMaven(maven: 'maven 3.5.2', jdk: 'JDK 9') {
sh 'mvn clean install' 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') { stage('Archiving') {
steps { steps {
archiveArtifacts 'pom.xml' archiveArtifacts '**/target/*.jar'
} }
} }
stage('Deploy') { stage('Deploy') {
when { expression { (env.GIT_BRANCH == 'master') } } when { expression { (env.GIT_BRANCH == 'master' && env.GIT_URL.startsWith('https://')) } }
steps { 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" sh "${mvn} deploy --activate-profiles release -DskipTests=true"
} }
} }