Skip to content
Snippets Groups Projects
Jenkinsfile 8.53 KiB
Newer Older
  • Learn to ignore specific revisions
  • OZGCloud's avatar
    OZGCloud committed
    def FAILED_STAGE
    
    
    OZGCloud's avatar
    OZGCloud committed
    pipeline {
    
    OZGCloud's avatar
    OZGCloud committed
        agent {
            node {
                label 'jenkins-worker'
            }
    
    OZGCloud's avatar
    OZGCloud committed
        }
    
    
        environment {
            BLUE_OCEAN_URL = "https://jenkins.ozg-sh.de/blue/organizations/jenkins/goofy/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') {
    
    OZGCloud's avatar
    OZGCloud committed
                                sh 'echo "registry=http://nexus.ozg-sh.de/repository/npm-proxy" >> ~/.npmrc'
                                sh 'echo "_auth=amVua2luczpQaihzX0ZNNFU5ZC8=" >> ~/.npmrc'
    
                                sh 'npm install --no-optional'
    
    OZGCloud's avatar
    OZGCloud committed
                            
                                if (env.BRANCH_NAME == 'release') {
                                    sh 'npm run ci-prodBuild'
                                }
                                else {
                                    sh 'npm run ci-build'
                                }
    
    OZGCloud's avatar
    OZGCloud committed
                                sh 'npm run ci-test'
    
    OZGCloud's avatar
    OZGCloud committed
    
    
    							try {
    	                            if (env.BRANCH_NAME == 'master') {
    	                                withSonarQubeEnv('sonarqube-ozg-sh'){
    	                                    sh 'npm run ci-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
                }
    
    OZGCloud's avatar
    OZGCloud committed
    //            post {
    //                always{
    //                    junit testResults: 'goofy-client/test-report.xml', skipPublishingChecks: true
    //                }
    //            }
    
    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
                        configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) {
    
                            sh 'mvn --version'
    
                            sh 'mvn -s $MAVEN_SETTINGS -pl -goofy-client clean install spring-boot:build-image -Dmaven.wagon.http.retryHandler.count=3'
    
    OZGCloud's avatar
    OZGCloud committed
                        }
    
    OZGCloud's avatar
    OZGCloud committed
    
                        script {
    
                        	try {
    	                        if (env.BRANCH_NAME == 'master') {
    	        	                dir('goofy-server'){
    	                                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
                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('Push Docker image') {
    
    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
    
    
    OZGCloud's avatar
    OZGCloud committed
                        container("docker") {
                            withCredentials([usernamePassword(credentialsId: 'jenkins-docker-login', usernameVariable: 'USER', passwordVariable: 'PASSWORD')]) {
                                sh 'docker login docker.ozg-sh.de -u ${USER} -p ${PASSWORD}'
    
    OZGCloud's avatar
    OZGCloud committed
    
    
    OZGCloud's avatar
    OZGCloud committed
                                sh "docker tag docker.ozg-sh.de/goofy:build-latest docker.ozg-sh.de/goofy:${env.BRANCH_NAME}-${version}"
                                sh "docker push docker.ozg-sh.de/goofy:${env.BRANCH_NAME}-${version}"
    
    OZGCloud's avatar
    OZGCloud committed
                                if (env.BRANCH_NAME == 'master') {
    
    OZGCloud's avatar
    OZGCloud committed
                                    sh 'docker tag docker.ozg-sh.de/goofy:build-latest docker.ozg-sh.de/goofy:e2e-test'
                                    sh 'docker push docker.ozg-sh.de/goofy:e2e-test'
    
    OZGCloud's avatar
    OZGCloud committed
            stage('E2E-Tests') {
    
    OZGCloud's avatar
    OZGCloud committed
                when {
                    branch 'master'
                }
                steps {
                    script {
                        FAILED_STAGE=env.STAGE_NAME
                    }
    
    OZGCloud's avatar
    OZGCloud committed
    
                    container("kubectl") {
                        sh 'kubectl rollout restart deployment/goofy -n sh-kiel-e2e'
                        sh 'kubectl rollout status deployment/goofy -n sh-kiel-e2e'
    
                        sh 'kubectl rollout restart deployment/pluto -n sh-kiel-e2e'
                        sh 'kubectl rollout status deployment/pluto -n sh-kiel-e2e'
                    }
    
                    container("cypress") {
    
    OZGCloud's avatar
    OZGCloud committed
                        dir('goofy-client') {
                            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('Deploy Maven Artifacts to Nexus') {
    
    OZGCloud's avatar
    OZGCloud committed
                when {
                    anyOf {
                        branch 'master'
                        branch 'release'
                    }
                }
                steps {
                    script {
                        FAILED_STAGE = env.STAGE_NAME
                    }
    
    OZGCloud's avatar
    OZGCloud committed
                        configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) {
    
    OZGCloud's avatar
    OZGCloud committed
                            sh 'mvn -s $MAVEN_SETTINGS -pl -goofy-client -DskipTests deploy'
                        }
    
    OZGCloud's avatar
    OZGCloud committed
            stage('Deploy Goofy') {
    
    OZGCloud's avatar
    OZGCloud committed
                when {
                    anyOf {
    
    OZGCloud's avatar
    OZGCloud committed
                        branch 'master'
    
    OZGCloud's avatar
    OZGCloud committed
                        branch 'release'
                    }
                }
    
    OZGCloud's avatar
    OZGCloud committed
                steps {
    
                    script {
                        FAILED_STAGE = env.STAGE_NAME
                    }
    
    OZGCloud's avatar
    OZGCloud committed
                    container("docker") {
                        script {
                            withCredentials([usernamePassword(credentialsId: 'jenkins-docker-login', usernameVariable: 'USER', passwordVariable: 'PASSWORD')]) {
                                sh 'docker login docker.ozg-sh.de -u ${USER} -p ${PASSWORD}'
    
    OZGCloud's avatar
    OZGCloud committed
                                
                                if (env.BRANCH_NAME == 'release') {
    
    OZGCloud's avatar
    OZGCloud committed
                                    sh 'docker tag docker.ozg-sh.de/goofy:build-latest docker.ozg-sh.de/goofy:latest'
                                    sh 'docker push docker.ozg-sh.de/goofy:latest'
    
    OZGCloud's avatar
    OZGCloud committed
                                }
    
    OZGCloud's avatar
    OZGCloud committed
    
    
    OZGCloud's avatar
    OZGCloud committed
                                if (env.BRANCH_NAME == 'master') {
                                    sh 'docker tag docker.ozg-sh.de/goofy:build-latest docker.ozg-sh.de/goofy:snapshot-latest'
                                    sh 'docker push docker.ozg-sh.de/goofy:snapshot-latest'
    
    OZGCloud's avatar
    OZGCloud committed
                                }
                            }
    
    OZGCloud's avatar
    OZGCloud committed
                        }
                    }
    
    OZGCloud's avatar
    OZGCloud committed
                    container("kubectl"){
                        script {
                            if (env.BRANCH_NAME == 'release') {
                                sh 'kubectl rollout restart deployment/goofy -n sh-kiel-test'
                                sh 'kubectl rollout status deployment/goofy -n sh-kiel-test'
                                sh 'kubectl rollout restart deployment/goofy -n sh-sl-test'
                                sh 'kubectl rollout status deployment/goofy -n sh-sl-test'
                            }
    
                            if (env.BRANCH_NAME == 'master') {
                                sh 'kubectl rollout restart deployment/goofy -n sh-kiel-dev'
                                sh 'kubectl rollout status deployment/goofy -n sh-kiel-dev'
                            }
                        }
                    }
    
    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
    }