@Library('utils') _

def mapBranchNameToWPEnv(branchName) {
    def envMap = [
        master: 'new_prod',
        main: 'new_prod',
        develop: 'dev',
        qa: 'qa',
        demo: 'demo'
    ]
    return envMap.get(branchName, 'development')
}

pipeline {
    agent any

    options {
        withFolderProperties()
    }

    environment {
        // LC_IMG_TAG = "${utils.mapBranchToEnv(env.BRANCH_NAME)}"
        LC_IMG_TAG = 'qa_test'
        WP_ENV = "${mapBranchNameToWPEnv(env.BRANCH_NAME)}"
    }

    stages {
        stage('Build') {
            steps {
                sh "docker build --build-arg ENV_NAME=${WP_ENV} -t ${env.PUSH_REGISTRY}/${env.LC_WP_IMG}:${LC_IMG_TAG} ."
                sh "docker push ${env.PUSH_REGISTRY}/${env.LC_WP_IMG}:${LC_IMG_TAG}"
            }
        }
    }
}