pipeline {
  agent any
  
  parameters {
    buildSelector(
      defaultSelector: lastSuccessful(),
      description: 'Which build to use for copying artifacts',
      name: 'BUILD_SELECTOR'
    )
  }

  stages {
    stage('Clone Repository') {
      steps {
        git branch: 'main', url: 'https://git.wmi.amu.edu.pl/s464913/ium_464913.git'
      }
    }
    stage('Copy Artifacts') {
      steps {
        copyArtifacts filter: 'data/*', projectName: 'z-s464913-create-dataset', selector: buildSelector('BUILD_SELECTOR')
      }
    }
    stage('Generate Report') {
      steps {
        sh 'chmod +x stats.sh'
        sh './stats.sh'
      }
    }
    stage('Archive Artifacts') {
      steps {
        archiveArtifacts artifacts: 'data/*', onlyIfSuccessful: true
      }
    }
  }
}