pipeline {
    agent { label 'apipod01' }

    environment {
        // Java 환경 설정
        JAVA_HOME = '/App/jenkins/jdks/jdk1.8.0_441'
        PATH = "${JAVA_HOME}/bin:${env.PATH}"

        // Gradle 환경 설정
        GRADLE_HOME = '/App/jenkins/gradle-8.7'
        GRADLE_USER_HOME = '/App/jenkins/gradle-home'
        // GRADLE_OPTS = '--offline'

        // Git 저장소 정보
        GIT_SERVER = '192.168.240.178:18081'
        GIT_CREDENTIALS_ID = 'git-ssh-credentials'

        // 프로젝트 디렉토리 구조
        PROJECT_HOME = '/Data/jenkins/eapim'

        BRANCH = 'jenkins_with_weblogic'
    }


    stages {
        stage('Git pull') {
            steps {
                echo "[admin] Git pull from branch: ${BRANCH}"
                dir("${PROJECT_HOME}/eapim-admin") {
                    git url: "ssh://git@${GIT_SERVER}/eapim/eapim-admin", branch: "${BRANCH}", credentialsId: "${GIT_CREDENTIALS_ID}"
                }


                echo "[online-core] Git pull from branch: ${BRANCH}"
                dir("${PROJECT_HOME}/eapim-online/elink-online-core") {
                    git url: "ssh://git@${GIT_SERVER}/eapim/elink-online-core", branch: "${BRANCH}", credentialsId: "${GIT_CREDENTIALS_ID}"
                }

                echo "[online-core-jpa] Git pull from branch: ${BRANCH}"
                dir("${PROJECT_HOME}/eapim-online/elink-online-core-jpa") {
                    git url: "ssh://git@${GIT_SERVER}/eapim/elink-online-core-jpa", branch: "${BRANCH}", credentialsId: "${GIT_CREDENTIALS_ID}"
                }


                echo "[online-transformer] Git pull from branch: ${BRANCH}"
                dir("${PROJECT_HOME}/eapim-online/elink-online-transformer") {
                    git url: "ssh://git@${GIT_SERVER}/eapim/elink-online-transformer", branch: "${BRANCH}", credentialsId: "${GIT_CREDENTIALS_ID}"
                }

                echo "[online-common] Git pull from branch: ${BRANCH}"
                dir("${PROJECT_HOME}/eapim-online/elink-online-common") {
                    git url: "ssh://git@${GIT_SERVER}/eapim/elink-online-common", branch: "${BRANCH}", credentialsId: "${GIT_CREDENTIALS_ID}"
                }

                echo "[online-emsclient] Git pull from branch: ${BRANCH}"
                dir("${PROJECT_HOME}/eapim-online/elink-online-emsclient") {
                    git url: "ssh://git@${GIT_SERVER}/eapim/elink-online-emsclient", branch: "${BRANCH}", credentialsId: "${GIT_CREDENTIALS_ID}"
                }

                echo "[portal-common] Git pull from branch: ${BRANCH}"
                dir("${PROJECT_HOME}/eapim-online/elink-portal-common") {
                    git url: "ssh://git@${GIT_SERVER}/eapim/elink-portal-common", branch: "${BRANCH}", credentialsId: "${GIT_CREDENTIALS_ID}"
                }


                echo "[kjb-safedb] Git pull from branch: ${BRANCH}"
                dir("${PROJECT_HOME}/kjb-safedb") {
                    git url: "ssh://git@${GIT_SERVER}/eapim/kjb-safedb", branch: "${BRANCH}", credentialsId: "${GIT_CREDENTIALS_ID}"
                }
            }
        }



        stage('Build') {
            steps {
                tool name: 'Oracle-JDK-1.8', type: 'hudson.model.JDK'

                echo "[admin] Build project"
                dir("${PROJECT_HOME}/eapim-admin") {
                    sh '${GRADLE_HOME}/bin/gradle clean build -x test -Pprofile=weblogic'
                }
            }
        }


        stage('Archive WAR') {
            steps {
                echo "[admin] Archive WAR file"
                dir("${PROJECT_HOME}/eapim-admin/build/libs") {
                    archiveArtifacts artifacts: '*.war', fingerprint: true
                }
            }
        }
    }
}