def isMaster = env.BRANCH_NAME == 'master'

node {
    stage('clean'){
        cleanWs()
    }
    stage('checkout'){
        checkout([$class: 'GitSCM',
            branches: [[name: '*/master']],
            doGenerateSubmoduleConfigurations: false,
            extensions: [],
            submoduleCfg: [],
            userRemoteConfigs: scm.userRemoteConfigs
        ])
        checkout scm
    }
    stage('lint') {
        withCredentials([file(credentialsId:'aws_config', variable:'AWS_CONFIG_FILE')]) {
            // skipping lint for now
            // sh 'make lint'
        }
    }
    stage('test') {
        withCredentials([file(credentialsId:'aws_config', variable:'AWS_CONFIG_FILE')]) {
            sh 'make test'
        }
    }
    stage('build') {
        withCredentials([file(credentialsId:'aws_config', variable:'AWS_CONFIG_FILE')]) {
            sh 'make build'
        }
    }
    stage('validate'){
        sh './bingo-out/primary/rackcheck validate --buildsheet-service-url https://buildsheet-service.us-west-2.prod.provisioner.live-video.a2z.com'
    }
    stage('upsert'){
        if (isMaster) {
            sh './bingo-out/primary/rackcheck sync --buildsheet-service-url https://buildsheet-service.us-west-2.prod.provisioner.live-video.a2z.com'
        } else {
            sh 'echo not upserting - not on master'
        }
    }
}
