pipeline {
    agent any
    parameters {
    string(name: 'KAGGLE_USERNAME', defaultValue: 'alicjaszulecka', description: 'Kaggle username')
    password(name: 'KAGGLE_KEY', defaultValue:'', description: 'Kaggle Key')
    string(name: 'CUTOFF', defaultValue: '100', description: 'cut off number')
    }
    stages {
        stage('Git Checkout') {
            steps {
               checkout scm
            }
        }
         stage('Download dataset') {
      steps {
        withEnv(["KAGGLE_USERNAME=${params.KAGGLE_USERNAME}", "KAGGLE_KEY=${params.KAGGLE_KEY}"]) {
          sh 'pip install kaggle'
          sh 'kaggle datasets download -d uciml/forest-cover-type-dataset'
          sh 'unzip -o forest-cover-type-dataset.zip'
          sh 'rm forest-cover-type-dataset.zip'
        }
      }
    }
     stage('Build') {
         steps {
            script {
                 withEnv(["KAGGLE_USERNAME=${params.KAGGLE_USERNAME}",
                          "KAGGLE_KEY=${params.KAGGLE_KEY}" ]) {
                    def customImage = docker.build("custom-image")
                    customImage.inside {
                        sh 'python3 ./IUM_2.py'
                        archiveArtifacts artifacts: 'covtype.csv, forest_train.csv, forest_test.csv, forest_val.csv', onlyIfSuccessful: true
                    }
                 }
             }
         }
         }

         stage('Train and Predict') {
            steps {
              script {
               def customImage = docker.build("custom-image")
                    customImage.inside {
                        sh 'python3 ./model.py'
                        sh 'python3 ./prediction.py'
                        archiveArtifacts artifacts: 'model.pth, predictions.txt', onlyIfSuccessful: true
                    }
              }
            }
        }
        stage('Experiments') {
            steps {
              script {
               def customImage = docker.build("custom-image")
                    customImage.inside {
                        sh 'python3 ./sacred_model.py'
                        archiveArtifacts artifacts: 'experiments', onlyIfSuccessful: true
                    }
              }
            }
        }
     }
}