node {
    stage('Deploy to Dev'){
        copyArtifacts(projectName: 'platform-builds/wso2-test-grid');
        sshagent(['testgrid-dev-key']) {
            sh """
                scp -o StrictHostKeyChecking=no web/target/*.war ${DEV_USER}@${DEV_HOST}:/testgrid/deployment/apache-tomcat-8.5.23/webapps/
                scp -o StrictHostKeyChecking=no distribution/target/*.zip ${DEV_USER}@${DEV_HOST}:/testgrid/jenkins-home/workspace
                """
           }
    }

    stage('Deploy to Prod'){
        def userInput
        try {
            userInput = input(
                    id: 'Proceed1', message: 'Deploy to Prod environment?', parameters: [
                    [$class: 'BooleanParameterDefinition', defaultValue: true, description: '', name: 'Please confirm you agree with this']
            ])
        } catch(err) { // input false
            def user = err.getCauses()[0].getUser()
            userInput = false
            echo "Aborted by: [${user}]"
        }

        if (userInput == true) {
            sshagent(['testgrid-prod-key']) {
                sh """
                    scp -o StrictHostKeyChecking=no web/target/*.war ${PROD_USER}@${PROD_HOST}:/testgrid/deployment/apache-tomcat-8.5.24/webapps/
                    scp -o StrictHostKeyChecking=no distribution/target/*.zip ${PROD_USER}@${PROD_HOST}:/testgrid/jenkins-home/workspace
                 """
            }
        } else {
            echo "Not proceeding with pre prod"
        }
    }

}
