pipeline {
  agent any
  
  parameters {
    string (
      defaultValue: 'vskyper',
      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',
    )
  }

  stages {
    stage('Clone Repository') {
      steps {
        git branch: 'main', url: 'https://git.wmi.amu.edu.pl/s464913/ium_464913.git'
      }
    }
    stage('Download Dataset') {
      steps {
        script {
          withEnv (["KAGGLE_USERNAME=${params.KAGGLE_USERNAME}", "KAGGLE_KEY=${params.KAGGLE_KEY}"]) {
            sh 'chmod +x download_dataset.sh'
            sh './download_dataset.sh'
          }
        }
      }
    }
    stage('Archive Artifacts') {
      steps {
        archiveArtifacts artifacts: 'data/*', onlyIfSuccessful: true
      }
    }
  }
}