|
|
@ -7,6 +7,7 @@ import javax.inject.Inject
|
|
|
|
import javax.ws.rs.*
|
|
|
|
import javax.ws.rs.*
|
|
|
|
import javax.ws.rs.core.MediaType
|
|
|
|
import javax.ws.rs.core.MediaType
|
|
|
|
import javax.ws.rs.core.Response
|
|
|
|
import javax.ws.rs.core.Response
|
|
|
|
|
|
|
|
import javax.ws.rs.core.Response.Status.PRECONDITION_REQUIRED
|
|
|
|
|
|
|
|
|
|
|
|
@Path("/builds")
|
|
|
|
@Path("/builds")
|
|
|
|
class BuildsEndpoint(
|
|
|
|
class BuildsEndpoint(
|
|
|
@ -35,19 +36,24 @@ class BuildsEndpoint(
|
|
|
|
fun trigger(@PathParam("build")
|
|
|
|
fun trigger(@PathParam("build")
|
|
|
|
build: String,
|
|
|
|
build: String,
|
|
|
|
@QueryParam("key")
|
|
|
|
@QueryParam("key")
|
|
|
|
key: String?) =
|
|
|
|
key: String?,
|
|
|
|
|
|
|
|
@QueryParam("rev")
|
|
|
|
|
|
|
|
rev: String?) =
|
|
|
|
security.requireKey(build, key) {
|
|
|
|
security.requireKey(build, key) {
|
|
|
|
val logFile = builds.createLogFile(build)
|
|
|
|
val logFile = builds.createLogFile(build)
|
|
|
|
|
|
|
|
|
|
|
|
startBuildThread(build, logFile, it)
|
|
|
|
if (rev == null) {
|
|
|
|
|
|
|
|
return@requireKey Response.status(PRECONDITION_REQUIRED).build()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
startBuildThread(build, rev, logFile, it)
|
|
|
|
|
|
|
|
|
|
|
|
Response.ok(mapOf(
|
|
|
|
Response.ok(mapOf(
|
|
|
|
"log" to logFile.absolutePath
|
|
|
|
"log" to logFile.absolutePath
|
|
|
|
))
|
|
|
|
)).build()
|
|
|
|
.build()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fun startBuildThread(build: String, logFile: File, config: BuildConfig) =
|
|
|
|
fun startBuildThread(build: String, rev: String, logFile: File, config: BuildConfig) =
|
|
|
|
Thread {
|
|
|
|
Thread {
|
|
|
|
logger.info("preparing process for build $build with config ${config.asPublic()}")
|
|
|
|
logger.info("preparing process for build $build with config ${config.asPublic()}")
|
|
|
|
logger.info("log file: $logFile")
|
|
|
|
logger.info("log file: $logFile")
|
|
|
@ -59,6 +65,7 @@ class BuildsEndpoint(
|
|
|
|
.apply {
|
|
|
|
.apply {
|
|
|
|
environment().putAll(config.env)
|
|
|
|
environment().putAll(config.env)
|
|
|
|
environment()["ALFRED_LOG_FILE"] = logFile.absolutePath
|
|
|
|
environment()["ALFRED_LOG_FILE"] = logFile.absolutePath
|
|
|
|
|
|
|
|
environment()["ALFRED_GIT_REV"] = rev
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.start()
|
|
|
|
.start()
|
|
|
|
.toHandle()
|
|
|
|
.toHandle()
|
|
|
|