pipeline {
    agent {
        dockerfile true
    }

	parameters {
		buildSelector(
					defaultSelector: lastSuccessful(),
					description: 'Which build to use for copying data artifacts',
					name: 'BUILD_SELECTOR_DATASET'
        )

        buildSelector(
					defaultSelector: lastSuccessful(),
					description: 'Which build to use for copying training artifacts',
					name: 'BUILD_SELECTOR_TRAINING'
        )
       
       buildSelector(
					defaultSelector: lastSuccessful(),
					description: 'Which build to use for copying evaluation artifacts',
					name: 'BUILD_SELECTOR_EVALUATION'
        )

        gitParameter branchFilter: 'origin/(.*)', defaultValue: 'master', name: 'BRANCH', type: 'PT_BRANCH'
   
	}

    stages {
    
        stage('copy artifacts')
                {
                    steps
                    {
                        copyArtifacts(fingerprintArtifacts: true, projectName: 's434742-create-dataset', selector: buildParameter('BUILD_SELECTOR_DATASET'))
                        copyArtifacts(fingerprintArtifacts: true, projectName: 's434742-training/${BRANCH}', selector: buildParameter('BUILD_SELECTOR_TRAINING'))
                        copyArtifacts(fingerprintArtifacts: true, optional:true, projectName: 's434742-evaluation/${BRANCH}', selector: buildParameter('BUILD_SELECTOR_EVALUATION'))
                    }
                }

        stage('evaluation') {
			steps {
                script {
             
                    sh "echo 'halko'"
                    sh 'chmod +x avocado-evaluation.py'
                    sh "echo ${env.BUILD_ID}"
                    sh "python3 avocado-evaluation.py ${env.BUILD_ID}"
                    sh 'python3 sacred-fileobserver.py'
                    sh 'python3 sacred-mongoobserver.py'
                
                }
			}
		}

        	stage('archiveArtifacts') {
			steps{
				archiveArtifacts 'eval_results.txt'
                archiveArtifacts 'eval_plot.png'
                archiveArtifacts 'sacred_runs/**'
			}
		}


        stage('sendMail') {
            steps{
                emailext body: "${currentBuild.currentResult}",
                subject: 's434742 evaluation',
                to: '26ab8f35.uam.onmicrosoft.com@emea.teams.ms'
            }
        }
    }
}