pipeline {
    agent {
        node {
            label 'master'
        }
    }
    stages {
        stage('install dependencies') {
            steps {
                nvm( version : '16.16.0' ){
                    sh 'npm install'
                }
            }
        }
        stage('build') {
            steps {
                nvm( version : '16.16.0' ){
                    sh 'npm run build'
                }
            }
        }
        stage('test') {
            steps {
                nvm( version : '16.16.0' ){
                    sh 'npm run test'
                }
            }
        }
        stage('deploy') {
            steps {
                script {
                    sshPublisher(
                        continueOnError: false, 
                        failOnError: true,
                        publishers: [
                            sshPublisherDesc(
                                configName: "ServerClubDit",
                                verbose: true,
                                transfers: [
                                    sshTransfer(
                                        sourceFiles: "build/**",
                                        removePrefix: "",
                                        remoteDirectory: "psicoadmin/"
                                    )
                                ]
                            )
                        ]
                    )
                }
            }
        }
    }
    post {
        always {
            slackSend channel: '#sysproy2',
                      color: currentBuild.currentResult == 'SUCCESS' ? 'good' : 'danger',
                      message: "*${currentBuild.currentResult}:* Job ${env.JOB_NAME} build ${env.BUILD_NUMBER} More info at: ${env.BUILD_URL}"
        }
    }

}
