#!/usr/bin/env groovy

pipeline {
    agent any

    stages {

        stage('Install') {
            steps {
                sh 'npm install'
             }
        }

        stage('Build') {
            steps {
                // that will run all the linting and tests
                sh "npm build"
            }
        }

        stage('Deploy') {

            when {
                // only deploy when all tests pass and on master branch
                expression { return (currentBuild.result == null || currentBuild.result == 'SUCCESS') && env.BRANCH_NAME == 'master' }
            }
            steps {
               // TODO: publish to npm
               echo "todo"
            }
        }
    }

    post {
        success {
            echo "success, with result: ${currentBuild.result}"
        }
        failure {
            echo "Build failed, with result: ${currentBuild.result}"

            slackSend (
                color: '#FFFF00',
                message: "${currentBuild.result}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' by ${env.CHANGE_AUTHOR_EMAIL} (${env.BUILD_URL})")
        }
    }
 }
