pipeline {
    agent any
	parameters{
		string(
			defaultValue: 'kaerde',
			description: 'Kaggle username',
			name: 'KAGGLE_USERNAME',
			trim: false
		)
		password(
			defaultValue: '',
			description: 'Kaggle token taken from kaggle.json file, as described in https://github.com/Kaggle/kaggle-api#api-credentials',
			name: 'KAGGLE_KEY'
		)
		string(
			defaultValue: '130000',
			description: 'data file cutoff threshold',
			name: 'CUTOFF'
		)
	}
    stages {
        stage('Stage 1') {
            steps {
				withEnv(["KAGGLE_USERNAME=${params.KAGGLE_USERNAME}",
				"KAGGLE_KEY=${params.KAGGLE_KEY}" ]) {
					echo 'Checking out...' 
					checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[credentialsId: 'f695fe86-8cca-47f7-a546-d3bfd1059fd4', url: 'https://git.wmi.amu.edu.pl/s449288/ium_s449288.git']]])
					echo 'Checked out' 
					echo 'Launching data processing script...' 
					sh 'chmod u+x ./skrypt.sh'
					sh './skrypt.sh $CUTOFF'
					echo 'Data processed' 
					echo 'Archiving results...' 
					archiveArtifacts 'lego_sets.tar.gz'
					echo 'Results archived'
				}
            }
        }		
    }
}