pipeline {
    options {
        timeout(time: 12, unit: 'MINUTES')
    }
    agent any

    environment {
        JOB_NAME = 'enterprise-policy-api_test'
        testServerIP = '192.168.1.7'
        productServerIP = '192.168.1.8'
    }

    parameters {
            booleanParam(name: 'FAST_MODE', defaultValue: false, description: '此操作将会跳过单元测试以及代码质量检查。')
    }

    stages {
        stage('pipeline环境准备') {

            steps {
                script {
                        echo "开始构建"
                        hostIP = ""
                        sh "echo 当前分支 : ${env.BRANCH_NAME}"
                        sh "echo 当前环境 : ${env.env}"
                        sh "echo 当前提交 : ${env.commit}"
                        sh "echo WORKSPACE : ${env.WORKSPACE}"
                        sh "echo GIT_BRANCH : ${env.GIT_BRANCH}"
                        sh "echo BUILD_NUMBER : ${env.BUILD_NUMBER}"
                        sh "echo JOB_NAME : ${env.JOB_NAME}"
                        sh "java -version"
                        if(env.BRANCH_NAME=="master"){
                            //开始打jar包
                            sh "mvn clean package -P prod -Dmaven.test.skip=true -U"
                            hostIP = productServerIP;
                        }
                        if(env.BRANCH_NAME=="test"){
                            //开始打jar包
                            sh "mvn clean package -P test -Dmaven.test.skip=true -U"
                            hostIP = testServerIP;
                        }
                        if(env.BRANCH_NAME=="dev"){
                             //开始打jar包
                            sh "mvn clean package -P dev -Dmaven.test.skip=true -U"
                        }
                        if(env.BRANCH_NAME=="dev"){
                            sh 'cp enterprise-policy/target/enterprise-policy-2.4.3.jar /vdb/www/9028-enterprise-policy-api'
                            sh 'cd /vdb/www/9028-enterprise-policy-api;source /etc/profile;sudo -su root ./shutdown.sh;sudo -su root ./startup.sh'
                         }else{
                            sh "scp enterprise-policy/target/enterprise-policy-2.4.3.jar ${hostIP}:/vdb/www/9028-enterprise-policy-api"
                            sh "ssh ${hostIP} \"source /etc/profile;cd /vdb/www/9028-enterprise-policy-api;./shutdown.sh;./startup.sh;\""
                         }
                }
            }
        }

    }
}
