Skip to content
Snippets Groups Projects
Jenkinsfile 6.38 KiB
Newer Older
  • Learn to ignore specific revisions
  • OZGCloud's avatar
    OZGCloud committed
    def FAILED_STAGE
    
    
    OZGCloud's avatar
    OZGCloud committed
    pipeline {
        agent {
            node {
    
    OZGCloud's avatar
    OZGCloud committed
                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"
        }
    
    
    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 {
    
    OZGCloud's avatar
    OZGCloud committed
                    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'
                            }
    
    OZGCloud's avatar
    OZGCloud committed
                        }
    
    OZGCloud's avatar
    OZGCloud committed
                    }
                }
    
    OZGCloud's avatar
    OZGCloud committed
                post {
                    always{
                        junit testResults: 'goofy-client/junit.xml', skipPublishingChecks: true
                        
                        publishHTML (target: [
                            allowMissing: false,
                            alwaysLinkToLastBuild: false,
                            keepAll: true,
                            reportDir: 'goofy-client/coverage/lcov-report',
                            reportFiles: 'index.html',
                            reportName: "Goofy-Client code coverage"
                        ])
                    }
                }
    
    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"){
    
    OZGCloud's avatar
    OZGCloud committed
                        sh 'mvn --version'
    
    
                        sh 'mvn -pl -goofy-client clean install'
    
    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
            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
    
            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
        }
    }