Newer
Older
def FAILED_STAGE
pipeline {
agent {
node {
label 'jenkins-worker'
}
}
environment {
BLUE_OCEAN_URL = "https://jenkins.ozg-sh.de/blue/organizations/jenkins/kop-common/detail/${env.BRANCH_NAME}/${env.BUILD_NUMBER}/pipeline"
RELEASE_REGEX = /\d+.\d+.\d+/
SNAPSHOT_REGEX = /\d+.\d+.\d+-SNAPSHOT/
}
options {
timeout(time: 1, unit: 'HOURS')
disableConcurrentBuilds()
buildDiscarder(logRotator(numToKeepStr: '5'))
}
stages {
steps {
script {
FAILED_STAGE = env.STAGE_NAME
def rootPom = readMavenPom file: 'pom.xml'
def rootVersion = rootPom.version
def dependenciesPom = readMavenPom file: 'kop-common-dependencies/pom.xml'
def dependenciesVersion = dependenciesPom.parent.version
def parentPom = readMavenPom file: 'kop-common-parent/pom.xml'

OZGCloud
committed
def parentVersion = parentPom.version
if(env.BRANCH_NAME == 'release'){
if ( !(rootVersion ==~ RELEASE_REGEX) || !(dependenciesVersion ==~ RELEASE_REGEX) || !(parentVersion ==~ RELEASE_REGEX)) {
error("Keine Release Version für Branch ${env.BRANCH_NAME}.")
}
} else {
if ( !(rootVersion ==~ SNAPSHOT_REGEX) || !(dependenciesVersion ==~ SNAPSHOT_REGEX) || !(parentVersion ==~ SNAPSHOT_REGEX)) {
error("Keine Snapshot Version für Branch ${env.BRANCH_NAME}.")
}
}
if( !(rootVersion == dependenciesVersion && rootVersion == parentVersion)){
error("Versionen sind nicht identisch")
}
}
}
stage('Build Kop-Common Dependencies') {
steps {
script {
FAILED_STAGE=env.STAGE_NAME
}
container("maven-17"){
dir('kop-common-dependencies') {
configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) {
sh 'mvn --version'
sh 'mvn -s $MAVEN_SETTINGS clean install'
}
}
}
}
}
stage('Build Kop-Common') {
steps {
script {
FAILED_STAGE=env.STAGE_NAME
}
container("maven-17"){
configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) {
sh 'mvn --version'
sh 'mvn -s $MAVEN_SETTINGS clean install'
try {
if (env.BRANCH_NAME == 'master') {
withSonarQubeEnv('sonarqube-ozg-sh'){
sh 'mvn sonar:sonar'
}
}
} catch (Exception e) {
unstable("SonarQube failed")
stage('Deploy Kop-Common to Nexus'){
when {
anyOf {
branch 'master'
branch 'release'
}
}
steps {
script {
FAILED_STAGE = env.STAGE_NAME
}
container('maven-17') {
configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) {
sh 'mvn -s $MAVEN_SETTINGS deploy'
}
}
}
}
}
post {
failure {
script {
if (env.BRANCH_NAME == 'master') {
//slackSend(color: "danger", message: "Kop-Common: Build Failed. Stage: ${FAILED_STAGE} Build-ID: <${BLUE_OCEAN_URL}|${env.BUILD_NUMBER}>")