pipeline {
   agent  { 
    dockerfile true 
}
   //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: 'd14370cec1714b0cd1ef2875038b5950',
                 description: 'Kaggle token taken from kaggle.json file, as described in https://github.com/Kaggle/kaggle-api#api-credentials',
                 name: 'KAGGLE_KEY'
             )
             string(
                 defaultValue: '0',
                 description: 'CUTOFF',
                 name: 'CUTOFF',
                 trim: false
             )
         }
    stages {
      stage('clear_all') {
         steps {
            //Wypisz wartość parametru w konsoli (To nie jest polecenie bash, tylko groovy!)
            sh 'rm -rf ium_z434686'
            sh 'rm -rf data/'
            sh 'rm -rf video-game-sales-with-ratings.zip'
         }
      }
      stage('checkout') {
         steps {
            //Wypisz wartość parametru w konsoli (To nie jest polecenie bash, tylko groovy!)
            sh 'git clone https://git.wmi.amu.edu.pl/s434686/ium_z434686'
         }
      }
      

      stage('Build') {
         steps {
         // Run the maven build
         withEnv(["KAGGLE_USERNAME=${params.KAGGLE_USERNAME}",
                  "KAGGLE_KEY=${params.KAGGLE_KEY}" ]) {
               sh 'kaggle datasets download -d rush4ratio/video-game-sales-with-ratings'
               sh 'ls -a | tee ls.txt'
               sh 'unzip video-game-sales-with-ratings.zip -d data'
               sh 'rm video-game-sales-with-ratings.zip'
               sh 'ls -a data/ | tee dataset.csv'
         }
         }
      }

     stage('Goodbye!') {
         steps {
            echo 'Goodbye!'
            //Zarchiwizuj wynik
            archiveArtifacts 'output.txt'
            archiveArtifacts 'ls.txt'
            archiveArtifacts 'dataset.csv'
            
         }
      }
   }
}