pipeline {
    agent { 
        dockerfile true 
    }
    parameters {
        string(name: 'batch_size', defaultValue: '512', description: 'size of batch')
        string(name: 'learning_rate', defaultValue: '0.01', description: 'Learning rate')
        string(name: 'epochs', defaultValue: '14', description: 'epochs')
    }
    stages {
        stage('Build') {
            steps {
//                 cleanWs()
                git 'https://git.wmi.amu.edu.pl/s434749/ium_434749.git'
                copyArtifacts fingerprintArtifacts: true, projectName: 's434749-create-dataset', selector: lastSuccessful()
                sh "python3 train_model.py with 'batch_size=${params.batch_size}' 'learning_rate=${params.learning_rate}' 'epochs=${params.epochs}'"
            }

            post {
                success {
                    emailext body: 'Training of CNN for english phonetic embeddings has finished successfully', subject: 's434749 training finished', to: '26ab8f35.uam.onmicrosoft.com@emea.teams.ms'
                    archiveArtifacts 'cnn.pth,sacred_file_observer/**'
                }
                failure{
                    emailext body: 'Training of CNN for english phonetic embeddings has failed!\n'+results, subject: 's434749 evaluation failed', to: '26ab8f35.uam.onmicrosoft.com@emea.teams.ms'
                }
                aborted{
                    emailext body: 'Training of CNN for english phonetic embeddings was aborted!\n'+results, subject: 's434749 evaluation aborted', to: '26ab8f35.uam.onmicrosoft.com@emea.teams.ms'
                }
            }
        }
    }
}