pipeline {
    agent { 
        dockerfile true 
    }

    parameters {
        string(
			defaultValue: '10000',
			name: 'CUTOFF',  
			description: 'Liczba wierszy do obcięcia ze zbioru danych')
	    string(
			defaultValue: '',
			name: 'KAGGLE_USERNAME',  
			description: 'Kaggle username')
        password(
			defaultValue: '',
			name: 'KAGGLE_KEY',  
			description: 'Kaggle API key') 
    }

    stages {
        stage('Clone Repository') {
            steps {
                checkout([$class: 'GitSCM', branches: [[name: '*/main']], userRemoteConfigs: [[url: 'https://git.wmi.amu.edu.pl/s464962/ium_464962']]])
            }
        }

        stage('Download') {
            steps {
                withEnv([
                    "KAGGLE_USERNAME=${env.KAGGLE_USERNAME}", 
                    "KAGGLE_KEY=${env.KAGGLE_KEY}"
                ]) {
                    sh "bash ./create-dataset.sh ${params.CUTOFF}"
                }
            }
        }
        stage('Train and predict') {
            steps {
                sh "chmod +x ./model.py"
                sh "chmod +x ./predict.py"
                sh "python ./model.py"
                sh "python ./predict.py"
                archiveArtifacts artifacts: 'car_prices_predict_model.h5, predicted_selling_prices.csv', onlyIfSuccessful: true
            }
        }
        stage('Archive Results') {
            steps {
                archiveArtifacts artifacts: 'data/*', onlyIfSuccessful: true
            }
        }
    }
}