def make(cmd) {
    sh "make ${cmd}"
}

pipeline {
    agent any
    options {
        disableConcurrentBuilds()
        timeout(time: 1, unit: 'HOURS')
        ansiColor('xterm')
        timestamps()
    }
    stages {
        stage('Build') {
            steps {
                sshagent(['git-aws-read-key']) {
                    make("jenkins-build")
                }
            }
        }
        stage('Upload Staging') {
            steps {
                echo "Uploading - Staging"
                make("jenkins-s3-upload-staging")
            }
        }
        stage('Upload Production') {
            when {
                branch 'master'
            }
            steps {
                echo "Uploading - Production"
                make("jenkins-s3-upload-production")
            }
        }

    }
}