node {
	checkout scm

	stage('Init') {
		properties([
			pipelineTriggers([ upstream(threshold: hudson.model.Result.SUCCESS, upstreamProjects: 's452639-create-dataset' ) ]),
			parameters([
				buildSelector(
					defaultSelector: lastSuccessful(),
					description: "Source of dataset",
					name: 'BUILD_SELECTOR'
				),
				string(
					defaultValue: "2",
					description: "Epochs count",
					name: "EPOCHS",
					trim: true
				),
			])
		])
	}

	def local_image = docker.build("s452639-image")

	local_image.inside {
		stage('Build') {
			checkout([$class: 'GitSCM', branches: [[name: BRANCH_NAME]], extensions: [], userRemoteConfigs: [[url: 'https://git.wmi.amu.edu.pl/s452639/ium_452639']]])

			copyArtifacts fingerprintArtifacts: true,
				projectName: 's452639-create-dataset',
				selector: lastSuccessful(),
				flatten: true,
				target: 'src/'

			sh "cd src; python tf_train_sacred.py with epochs=${params.EPOCHS}"
			archiveArtifacts artifacts: 'src/model.keras,src/experiments/**/*', followSymlinks: false
		}
	}

	stage('Trigger') {
		build wait: false, job: 's452639-evaluation.eg'
	}
}