import groovy.json.JsonSlurper
import groovy.json.JsonOutput

properties([
    parameters([
        string(name: 'GIT_COMMIT', defaultValue: '', description: 'Git Sha', ),
        string(name: 'ENVIRONMENT', defaultValue: '', description: 'Environment', ),
        string(name: 'SKADI_ID', defaultValue: '', description: 'Environment', )
    ])
])

pipeline {
    agent any

    options {
        disableConcurrentBuilds()
        timeout(time: 8, unit: 'MINUTES')
        ansiColor('xterm')
        timestamps()
    }

    environment {
        REGION = "us-west-2"
        CLUSTER = "sonar"
        ENVIRONMENT = "${params.ENVIRONMENT}"
    }

    stages {
        stage('Deploy to Staging') {
            when {
                expression { params.ENVIRONMENT == 'staging' }
            }

            environment {
                SERVICE = "destiny"
                SHA = "${params.GIT_COMMIT}"
            }

            steps {
                withCredentials([
                    string(credentialsId: 'twitch-subs-dev-tcs-access-key', variable: 'AWS_ACCESS_KEY_ID'),
                    string(credentialsId: 'twitch-subs-dev-tcs-secret-key', variable: 'AWS_SECRET_ACCESS_KEY'),
                    file(credentialsId: 'aws_config', variable: 'AWS_CONFIG_FILE')
                ]) {
                    sh "./jenkins/deploy.sh"
                }
            }
        }
    }
}
