pipeline {
    agent {dockerfile true}	
	options {
        copyArtifactPermission('s434684-evaluation/master');
    }
	parameters {
		buildSelector(
					defaultSelector: lastSuccessful(),
					description: 'Which build to use for copying artifacts',
					name: 'BUILD_SELECTOR')
		string(name: 'LEARNING_RATE', defaultValue: '0.0001', description: 'What should be the learning rate?')
	}
    stages {
		stage('copyArtifacts') {
            steps {
                copyArtifacts fingerprintArtifacts: true, projectName: 's434684-create-dataset', selector: buildParameter('BUILD_SELECTOR')
            }
        }
		stage('Sh script') {
			steps {
                sh 'chmod +x run_training.sh'
				withEnv(["LEARNING_RATE=${params.LEARNING_RATE}"]) {
				sh './run_training.sh $LEARNING_RATE'
                }
			
			}
		}
		stage('Archive artifacts') {
			steps{
				archiveArtifacts artifacts: 'model_movies.h5,my_runs/**'
			}
		}
    }
	 post {
        success {

            build job: 's434684-evaluation/master'
            mail body: 'SUCCESS',
                subject: 's434684-training',
                to: '26ab8f35.uam.onmicrosoft.com@emea.teams.ms'
        }
        failure {
            mail body: 'FAILURE', subject: 's434684-training', to: '26ab8f35.uam.onmicrosoft.com@emea.teams.ms'
        }
    }
}