pipeline {
    agent any
    triggers {
        upstream(upstreamProjects: 'z-s464914-create-dataset', threshold: hudson.model.Result.SUCCESS)
    }
    parameters {
            buildSelector (
                defaultSelector: lastSuccessful(),
                description: 'Build for copying artifacts',
                name: 'BUILD_SELECTOR'
            )
            string(name: 'EPOCHS', defaultValue: '10', description: 'epochs')
        }
    stages {
        stage('Git Checkout') {
            steps {
               checkout scm
            }
        }
     stage('Copy Artifacts') {
            steps {
               copyArtifacts fingerprintArtifacts: true, projectName: 'z-s464914-create-dataset', selector: buildParameter('BUILD_SELECTOR')
            }
        }
         stage('Train') {
            steps {
              script {
               def customImage = docker.build("custom-image")
                    customImage.inside {
                        sh 'python3 ./model.py ' + params.EPOCHS
                        archiveArtifacts artifacts: 'model.pth, predictions.txt', onlyIfSuccessful: true
                    }
              }
            }
        }
     }
}