Skip to content
Snippets Groups Projects
Jenkinsfile 7.55 KiB
Newer Older
  • Learn to ignore specific revisions
  • OZGCloud's avatar
    OZGCloud committed
    def FAILED_STAGE
    
    
    OZGCloud's avatar
    OZGCloud committed
    pipeline {
    
        agent any
        tools {
    	    maven 'maven3'
    	    jdk 'jdk11'
    
    OZGCloud's avatar
    OZGCloud committed
    	    nodejs 'node14'
    
    	} 
        //{
           // node {
             //   label 'goofy'
            //}
        //}
    
    OZGCloud's avatar
    OZGCloud committed
    
    
    OZGCloud's avatar
    OZGCloud committed
        environment {
    
            //BLUE_OCEAN_URL = "https://jenkins-dev-tools.apps.lab.okd.local/blue/organizations/jenkins/OZG%2Fgoofy/detail/${env.BRANCH_NAME}/${env.BUILD_NUMBER}/pipeline"
            BLUE_OCEAN_URL = "https://jenkins.ozg-sh.de/blue/organizations/jenkins/OZG%2Fgoofy/detail/${env.BRANCH_NAME}/${env.BUILD_NUMBER}/pipeline"
    
    OZGCloud's avatar
    OZGCloud committed
        }
    
    
    OZGCloud's avatar
    OZGCloud committed
        options {
            timeout(time: 1, unit: 'HOURS')
            disableConcurrentBuilds()
    
    OZGCloud's avatar
    OZGCloud committed
            buildDiscarder(logRotator(numToKeepStr: '5'))
    
    OZGCloud's avatar
    OZGCloud committed
        }
    
        stages {
    
    OZGCloud's avatar
    OZGCloud committed
            stage('Client') {
    
    OZGCloud's avatar
    OZGCloud committed
                steps {
    
    //                container("nodejs"){
    
    OZGCloud's avatar
    OZGCloud committed
                        script {
                            FAILED_STAGE=env.STAGE_NAME
    
                            sh 'npm --version'
                            dir('goofy-client') {
                                sh 'npm install'
                            
                                if (env.BRANCH_NAME == 'release') {
                                    sh 'npm run ci-prodBuild'
                                }
                                else {
                                    sh 'npm run ci-build'
                                }
    
    
                                sh 'npm run ci-test'
    
                                if (env.BRANCH_NAME == 'master') {
                                    withSonarQubeEnv('sonarqube'){
                                        sh 'npm run ci-sonar'
                                    }
    
    OZGCloud's avatar
    OZGCloud committed
                                }
    
    OZGCloud's avatar
    OZGCloud committed
                            }
    
    OZGCloud's avatar
    OZGCloud committed
                        }
    
    OZGCloud's avatar
    OZGCloud committed
                    //gi}
    
    OZGCloud's avatar
    OZGCloud committed
                }
    
    OZGCloud's avatar
    OZGCloud committed
                post {
                    always{
    
    OZGCloud's avatar
    OZGCloud committed
                        junit testResults: 'goofy-client/test-report.xml', skipPublishingChecks: true
    
    OZGCloud's avatar
    OZGCloud committed
                    }
                }
    
    OZGCloud's avatar
    OZGCloud committed
            }
    
    
    OZGCloud's avatar
    OZGCloud committed
            stage('Server') {
    
    OZGCloud's avatar
    OZGCloud committed
                steps {
    
    OZGCloud's avatar
    OZGCloud committed
                    script {
                        FAILED_STAGE=env.STAGE_NAME
                    }
    
    OZGCloud's avatar
    OZGCloud committed
                    container("maven-11"){
    
                        configFileProvider([configFile(fileId: '9aac2fac-7d8d-4128-846b-0a61951df703', variable: 'MAVEN_SETTINGS')]) {
                            sh 'mvn --version'
                            sh 'mvn -s $MAVEN_SETTINGS -pl -goofy-client clean install'
    
    
    OZGCloud's avatar
    OZGCloud committed
                            script {
                                if (env.BRANCH_NAME == 'master') {
            	                    dir('goofy-server'){
                                        withSonarQubeEnv('sonarqube'){
                                            sh 'mvn sonar:sonar'
                                        }
    
    OZGCloud's avatar
    OZGCloud committed
    		                    }
                            }
    
    OZGCloud's avatar
    OZGCloud committed
                        }
    
    OZGCloud's avatar
    OZGCloud committed
                    }
                }
    
    OZGCloud's avatar
    OZGCloud committed
                post {
                    always{
                        junit testResults: '**/target/surefire-reports/*.xml', skipPublishingChecks: true
                    }
                }
    
    OZGCloud's avatar
    OZGCloud committed
            } 
    
    OZGCloud's avatar
    OZGCloud committed
    
    
    OZGCloud's avatar
    OZGCloud committed
            stage('Openshift build') {
    
    OZGCloud's avatar
    OZGCloud committed
                steps {
                    script {
    
    OZGCloud's avatar
    OZGCloud committed
                        FAILED_STAGE=env.STAGE_NAME
    
    OZGCloud's avatar
    OZGCloud committed
                        def pom = readMavenPom file: 'pom.xml'
                        def version = pom.version
    
                        openshift.withCluster() {
                            openshift.withProject() {
                                dir('goofy-server') {
    
    OZGCloud's avatar
    OZGCloud committed
                                    openshift.startBuild("goofy-builder", "--from-dir=.", "--follow", "--wait")
    
    OZGCloud's avatar
    OZGCloud committed
                                }
                             
    
    OZGCloud's avatar
    OZGCloud committed
                                openshift.tag("goofy-builder:build-latest", "goofy-builder:${env.BRANCH_NAME}-${version}")
    
    OZGCloud's avatar
    OZGCloud committed
    
    
    OZGCloud's avatar
    OZGCloud committed
                                if (env.BRANCH_NAME == 'release') {
                                    openshift.tag("goofy-builder:${env.BRANCH_NAME}-${version}", "goofy-builder:latest")
                                }
    
    
    OZGCloud's avatar
    OZGCloud committed
                                if (env.BRANCH_NAME == 'master') {
                                    def dc = openshift.selector('dc', 'goofy-e2e')
    
    OZGCloud's avatar
    OZGCloud committed
    
                                    openshift.tag("goofy-builder:${env.BRANCH_NAME}-${version}", "goofy-builder:snapshot-latest")
    
    OZGCloud's avatar
    OZGCloud committed
                                    openshift.tag("goofy-builder:${env.BRANCH_NAME}-${version}", "goofy-builder:e2e-latest")
    
    OZGCloud's avatar
    OZGCloud committed
                                    dc.rollout().status()
                                }
                            }
                        }
                    }
                }
            }
    
    
    OZGCloud's avatar
    OZGCloud committed
            stage('E2E-Test') {
                when {
                    branch 'master'
                }
                steps {
                    script {
                        FAILED_STAGE=env.STAGE_NAME
                    }
                    container("cypress"){
                        sh 'npm --version'
                        dir('goofy-client') {
                            sh 'npm install'
                            sh 'npm run cypress:version'
                            sh 'npm run cypress:ci-run'
                        }
                    }
                }
                post {
                    always {
                        publishHTML (target: [
                        allowMissing: false,
                        alwaysLinkToLastBuild: false,
                        keepAll: true,
                        reportDir: 'goofy-client/apps/goofy-e2e/reports',
                        reportFiles: 'report.html',
                        reportName: "Goofy E2E-Tests"
                        ])
                    }
                }
            }
    
    OZGCloud's avatar
    OZGCloud committed
    
    
    OZGCloud's avatar
    OZGCloud committed
            stage('nexus deploy'){
                when {
                    anyOf {
                        branch 'master'
                        branch 'release'
                    }
                }
                steps {
                    script {
                        FAILED_STAGE = env.STAGE_NAME
                    }
                    container('maven-11') {
    
    OZGCloud's avatar
    OZGCloud committed
                        configFileProvider([configFile(fileId: '9aac2fac-7d8d-4128-846b-0a61951df703', variable: 'MAVEN_SETTINGS')]) {
                            sh 'mvn -s $MAVEN_SETTINGS -pl -goofy-client -DskipTests deploy'
                        }
    
    OZGCloud's avatar
    OZGCloud committed
            stage('Openshift deploy') {
                when {
                    anyOf {
                        branch 'master';
                        branch 'release'
                    }
                }
                steps {
                    script {
                        FAILED_STAGE=env.STAGE_NAME
                        def pom = readMavenPom file: 'pom.xml'
                        def version = pom.version
    
                        openshift.withCluster() {
                            openshift.withProject() {
    
    OZGCloud's avatar
    OZGCloud committed
                                openshift.tag("goofy-builder:${env.BRANCH_NAME}-${version}", "sh-kiel-dev/goofy:${env.BRANCH_NAME}-${version}")
    
    OZGCloud's avatar
    OZGCloud committed
                                
                                if (env.BRANCH_NAME == 'master') {
                                    openshift.tag("goofy-builder:snapshot-latest", "sh-kiel-dev/goofy:snapshot-latest")
                                }
    
                                if (env.BRANCH_NAME == 'release') {
                                    openshift.tag("goofy-builder:latest", "sh-kiel-dev/goofy:latest")
                                }
    
    OZGCloud's avatar
    OZGCloud committed
                            }
                            if (env.BRANCH_NAME == 'master') {
                                openshift.withProject('sh-kiel-dev') {
                                    def dc = openshift.selector('deployments', 'goofy')
    
                                    dc.rollout().status()
                                }
                            }
    
    OZGCloud's avatar
    OZGCloud committed
                        }
                    }
                }
    
    OZGCloud's avatar
    OZGCloud committed
            }
        }
        post {
            failure {
                script {
                    if (env.BRANCH_NAME == 'master') {
                        slackSend(color: "danger", message: "Goofy: Build Failed. Stage: ${FAILED_STAGE} Build-ID: <${BLUE_OCEAN_URL}|${env.BUILD_NUMBER}>")
                    }
                }
            }
    
    OZGCloud's avatar
    OZGCloud committed
        }
    }