pipeline {
   agent  any

   //Definijuemy parametry, które będzie można podać podczas wywoływania zadania
         parameters{
             string(
                 defaultValue: 'patrykgaka',
                 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: '500',
                 description: 'CUTOFF',
                 name: 'CUTOFF',
                 trim: false
             )
         }
    stages {
      stage('clear_before') {
         steps {
            sh 'rm -rf *'
         }
      }

      stage('Clone Git') {
         steps {
            sh 'git clone https://git.wmi.amu.edu.pl/s434686/ium_z434686'
         }
      }

      stage('Build') {
         steps {
         withEnv(["KAGGLE_USERNAME=${params.KAGGLE_USERNAME}",
                  "KAGGLE_KEY=${params.KAGGLE_KEY}" ]) {
               sh 'kaggle datasets download -d rush4ratio/video-game-sales-with-ratings'
               sh 'unzip video-game-sales-with-ratings.zip -d ./ium_z434686'
            }
         }
      }
      stage('Docker') {
         agent { 
            dockerfile {
               filename 'Dockerfile'
               dir      'ium_z434686'
               reuseNode true
            }
         }
         steps {
                  sh 'python ./ium_z434686/create-dataset.py'
                  archiveArtifacts 'X_test.csv'
                  archiveArtifacts 'X_dev.csv'
                  archiveArtifacts 'X_train.csv'
         }
      }
      stage('clear_after') {
         steps {
            sh 'rm -rf *'
         }
      }
   }
}