
@Library("cicdhtj@master") _
def repos = [
    // [dir: 'BASE', type: 'mvn', isUpdate: true, url: 'http://114.116.202.8:18808/factory-tobacco/factory-tobacco-basic.git'],
    // [dir: 'CORE', type: 'mvn', isUpdate: true, url: 'http://114.116.202.8:18808/factory-tobacco/factory-tobacco-qrcodecore.git'],
    // [dir: 'HTJ', type: 'mvn', isUpdate: true, url: 'http://114.116.202.8:18808/factory-tobacco/factory-tobacco-qrcode-htj.git'],
    // [dir: 'WEB', type: 'node', isUpdate: true, url: 'http://114.116.202.8:18808/factory-tobacco/factory-tobacco-qrcode-htj-vue.git']
]
def modules = [
    [dir: 'BASE', name: "factory-tobacco-qrcode-auth", version: "v24.09.20", isUpdate: true, isEncryption: true,path: "module/xxx/xxxx"]

]


pipeline {
    agent any

    parameters {
        gitParameter branchFilter: 'origin/(.*)', defaultValue: 'master', name: 'BASE', type: 'PT_BRANCH_TAG', useRepository: '.*factory-tobacco-basic.git' // 后端
        gitParameter branchFilter: 'origin/(.*)', defaultValue: 'master', name: 'CORE', type: 'PT_BRANCH_TAG', useRepository: '.*factory-tobacco-qrcodecore.git' // 后端
        gitParameter branchFilter: 'origin/(.*)', defaultValue: 'master', name: 'HTJ', type: 'PT_BRANCH_TAG', useRepository: '.*factory-tobacco-qrcode-htj.git' // 后端
        gitParameter branchFilter: 'origin/(.*)', defaultValue: 'master', name: 'WEB', type: 'PT_BRANCH_TAG', useRepository: '.*factory-tobacco-qrcode-htj-vue.git' // 后端
    }

    tools {
        jdk 'jdk8'
        nodejs 'nodejs16'
        maven 'maven3.9'
    }

    stages {
        stage('步骤一: 参数获取') {
            steps {
                script {
                    def yamlFile = readFile('project.yaml')
                    def smallfile = log.readYaml(yamlFile)
                    repos.add([dir: smallfile.base.name, type: smallfile.base.type, isUpdate: smallfile.base.isUpdate, url: smallfile.base.url])
                    repos.add([dir: smallfile.core.name, type: smallfile.core.type, isUpdate: smallfile.core.isUpdate, url: smallfile.core.url])
                    repos.add([dir: smallfile.htj.name, type: smallfile.htj.type, isUpdate: smallfile.htj.isUpdate, url: smallfile.htj.url])
                    repos.add([dir: smallfile.web.name, type: smallfile.web.type, isUpdate: smallfile.web.isUpdate, url: smallfile.web.url])
//                     base = xxx.base.module
//                     core = xxx.core.module
//                     htj = xxx.htj.module
//                     web = xxx.web
//                     // 遍历 base 对象（假设 base 是一个集合）
//                     if (base instanceof List) {
//                         base.each { item ->
//                             echo "Base Item: ${item.name}" // 输出每个项的内容
//                         }
//                     } else {
//                         echo "Base is not a list"
                    // }
                }
            }
        }
        stage('步骤一: 代码获取') {
            steps {
                script {
                    for (repo in repos) {
                        dir(repo.dir) {
                            git branch: "${params[repo.dir]}", credentialsId: '175beac7-7b6f-4171-a605-a268377d2937', url: repo.url
                        }
                    }   
                }
            }
        }

        stage('步骤二: 项目构建'){
            steps {
                script {
                    for (repo in repos) {
                        dir(repo.dir) {
                            if ( repo.isUpdate && repo.type == 'mvn') sh "mvn -T 1C -Dmaven.test.failure.ignore=true clean package install"
                            else if ( repo.isUpdate && repo.type == 'node') sh "npm run build:prod-htj"

                        }
                    }
                }
            }
        }
        stage('步骤三: 加密并拷贝文件'){
            steps {
                script {
                    sh "echo '加密并拷贝文件'"
                }
                // for (module in modules){
//                     dir(module.dir) {
//                         sh "cd ${module.path}/target/ && ls -la "
// //                         if (module.isEncryption){
// //                             sh "cd ${module.path} && mvn classfinal:classFinal"
// //                             sh "cd ${module.path}/target/ && ls -la "
// //                         }

//                     }
                // }
            }
        }
    }
}
