@Library('jenkins-shared-library') _


def repos = [
    [dir: 'BASE', batch:'master', url: 'http://114.116.202.8:18808/factory-tobacco/factory-tobacco-basic.git'],
    [dir: 'CORE', batch:'master',  url: 'http://114.116.202.8:18808/factory-tobacco/factory-tobacco-qrcodecore.git'],
    [dir: 'HTJ', batch:'master',  url: 'http://114.116.202.8:18808/factory-tobacco/factory-tobacco-qrcode-htj.git'],
    [dir: 'WEB', batch:'master',  url: 'http://114.116.202.8:18808/factory-tobacco/factory-tobacco-qrcode-htj-vue.git']
]

def smallfile


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' // 后端
//         for (repo in repos) {
//             gitParameter branchFilter: 'origin/(.*)', defaultValue: repo.batch , name: repo.dir, type: 'PT_BRANCH_TAG', useRepository: repo.url // 后端
//         }

    }

    stages {
        // stage('步骤一: 参数获取') {
        //     steps {
        //         script {
        //             def yamlFile = readFile('project.yaml')
        //             def smallfile = log.readYaml(yamlFile)

//                     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) {
                        properties([
                            parameters([
                                gitParameter(branchFilter: 'origin/(.*)', 
                                             defaultValue: repo.batch, 
                                             name: repo.dir, 
                                             type: 'PT_BRANCH_TAG', 
                                             useRepository: repo.url)
                            ])
                        ])
                    }
                }
            }
        }

        stage('步骤二: 代码获取'){
            steps {
                script {
                    for (repo in repos) {
                        dir(repo.dir) {
                            git branch: "${params.[repo.dir]}", credentialsId: '0fba0f76-d958-4800-8165-cad2442392ff', url: repo.url
                        }
                    }   
                }
            }
        }

        stage('步骤二: 基础模块构建'){
            steps {
                script {
                    dir('BASE') {
                        // 执行构建命令
                    }
                }
            }

        }
        stage('步骤三: 核心模块构建'){
            steps {
                script {
                    dir('BASE') {
                        // 执行构建命令
                    }
                }
            }


        }
        stage('步骤四: HTJ模块构建'){
            steps {
                script {
                    dir('BASE') {
                        // 执行构建命令
                    }
                }
            }


        }
        stage('步骤五: Web模块构建'){
            steps {
                script {
                    dir('BASE') {
                        // 执行构建命令
                    }
                }
            }

        }

    }
}
