pipeline {
    agent any
    stages {
        stage('build') {
            steps {
                script {
                    if(env.JOB_NAME == 'DEV_Inversys_frontend'){
                        sh  '''
                            cd /opt/inversys/app/frontend/
                            git pull
                            '''
                    }
                    else if(env.JOB_NAME == 'TST_Inversys_frontend'){
                        sshagent(credentials: ['deployment-key']) {
                            sh  '''
                                ssh deploy@192.168.98.48 'cd /opt/inversys/app/frontend/ && git pull'
                                '''
                        }
                    }
                }                
            }
        }
        stage('Test') {
            steps {
                echo 'Testing..'
            }
        }
        stage('Deploy') {
            steps {
                script {
                    if(env.JOB_NAME == 'DEV_Inversys_frontend'){
                        sh  '''
                            cd /opt/inversys/
                            docker-compose up -d --build frontend
                            '''
                    }
                    else if(env.JOB_NAME == 'TST_Inversys_frontend'){
                        sshagent(credentials: ['deployment-key']) {
                            sh  '''
                                ssh deploy@192.168.98.48 'cd /opt/inversys/ && docker-compose up -d --build frontend'
                                '''
                        }
                    }
                }                
            }
        }
    }
}