Skip to content
Snippets Groups Projects
Jenkinsfile 4.47 KiB
Newer Older
  • Learn to ignore specific revisions
  • 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 {
    
    /*        stage('Check Version') {
    
                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'
    
    
                        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'
    
    OZGCloud's avatar
    OZGCloud committed
                    
    
    OZGCloud's avatar
    OZGCloud committed
                    
    	                script {
    
    OZGCloud's avatar
    OZGCloud committed
    	              	    dir('kop-common-lib') {
    
    OZGCloud's avatar
    OZGCloud committed
    	                    	try {
    		                        if (env.BRANCH_NAME == 'master') {
    		                            withSonarQubeEnv('sonarqube-ozg-sh'){
    										sh 'mvn sonar:sonar'	                                
    		                            }
    		                        }
    		                    } catch (Exception e) {
    	                               unstable("SonarQube failed")
    
    OZGCloud's avatar
    OZGCloud committed
    	                        }
    
    OZGCloud's avatar
    OZGCloud committed
    	                    }
    
    OZGCloud's avatar
    OZGCloud committed
    	               }
    
    OZGCloud's avatar
    OZGCloud committed
                    }
                }
    
    OZGCloud's avatar
    OZGCloud committed
             }
    
    
            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}>")