pipeline {
    agent {
        node {
            label 'goofy'
        }
    }

    options {
        timeout(time: 1, unit: 'HOURS')
        disableConcurrentBuilds()
    }

    stages {
        stage('client build') {
            steps {
                container("nodejs"){
                    sh 'npm --version'
                    dir('goofy-client') {
                        sh 'npm install'
                        sh 'npm run build'
                        sh 'npm run test'
                    }
                }
            }
        }

        stage('server build') {
            steps {
                container("maven"){
                    sh 'mvn --version'

                    sh 'mvn -pl -goofy-client clean install'
                }
            }
        }

        stage('openshift deploy') {
            steps {
                script {
                    def pom = readMavenPom file: 'pom.xml'
                    def version = pom.version

                    openshift.withCluster() {
                        openshift.withProject() {
                            dir('goofy-server') {
                                openshift.startBuild("goofy-builder", "--from-dir=.", "--follow", "--wait")
                            }
                         
                            openshift.tag("goofy-builder:latest", "goofy-builder:${env.BRANCH_NAME}-${version}")
                            openshift.tag("goofy-builder:${env.BRANCH_NAME}-${version}", "sh-kiel-dev/goofy:${env.BRANCH_NAME}-${version}")
                        }                    
                    }
                }
            }
        }    
    }
}