|
|
|
@ -30,7 +30,7 @@ class GitRunner(
|
|
|
|
|
val config = builds.buildConfig(buildId)
|
|
|
|
|
val logFile = builds.createLogFile(buildId)
|
|
|
|
|
|
|
|
|
|
logger.info("preparing process for build $buildId with config $config")
|
|
|
|
|
logger.info("preparing process for build $buildId")
|
|
|
|
|
logger.info("log file: $logFile")
|
|
|
|
|
|
|
|
|
|
val ctx = BuildContext(
|
|
|
|
@ -55,38 +55,43 @@ class GitRunner(
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun clone(ctx: BuildContext, wsPath: Path) {
|
|
|
|
|
logger.info("build ${ctx.buildId}: cloning ${ctx.config.gitRepo} into $wsPath")
|
|
|
|
|
ctx.log("build ${ctx.buildId}: cloning ${ctx.config.gitRepo} into $wsPath")
|
|
|
|
|
|
|
|
|
|
val process = processes.builder(ctx.config, ctx.logFile, "")
|
|
|
|
|
val cloneProc = processes.builder(ctx.config, ctx.logFile, "")
|
|
|
|
|
.command("git", "clone", ctx.config.gitRepo, ".")
|
|
|
|
|
.directory(wsPath.toFile())
|
|
|
|
|
.start()
|
|
|
|
|
handles.add(Handle(process.toHandle(), ctx.buildId))
|
|
|
|
|
val cloneSuccess = process.waitFor(ctx.config.gitCloneTimeout, TimeUnit.SECONDS)
|
|
|
|
|
handles.add(Handle(cloneProc.toHandle(), ctx.buildId))
|
|
|
|
|
|
|
|
|
|
logger.info("build ${ctx.buildId}: checkout rev ${ctx.rev}")
|
|
|
|
|
processes.builder(ctx.config, ctx.logFile, "")
|
|
|
|
|
val cloneSuccess = cloneProc.waitFor(ctx.config.gitCloneTimeout, TimeUnit.SECONDS)
|
|
|
|
|
if (!cloneSuccess) {
|
|
|
|
|
throw FailedToClone(ctx.buildId, ctx.config.gitRepo ?: "[no repo configured]")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ctx.log("build ${ctx.buildId}: checkout rev ${ctx.rev}")
|
|
|
|
|
val checkoutProc = processes.builder(ctx.config, ctx.logFile, "")
|
|
|
|
|
.command("git", "checkout", ctx.rev)
|
|
|
|
|
.directory(wsPath.toFile())
|
|
|
|
|
.start()
|
|
|
|
|
.waitFor()
|
|
|
|
|
handles.add(Handle(checkoutProc.toHandle(), ctx.buildId))
|
|
|
|
|
|
|
|
|
|
if (!cloneSuccess) {
|
|
|
|
|
throw FailedToClone(ctx.buildId, ctx.config.gitRepo ?: "[no repo configured]")
|
|
|
|
|
val checkoutSuccess = checkoutProc.waitFor(ctx.config.gitCloneTimeout, TimeUnit.SECONDS)
|
|
|
|
|
if (!checkoutSuccess) {
|
|
|
|
|
throw FailedToCheckout(ctx.buildId, ctx.config.gitRepo!!, ctx.rev)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun execScripts(ctx: BuildContext, wsPath: Path) {
|
|
|
|
|
val scriptFiles = listOf("pre.sh", "job.sh", "post.sh")
|
|
|
|
|
|
|
|
|
|
logger.info("build ${ctx.buildId}: looking for scripts $scriptFiles in $scriptsDir/")
|
|
|
|
|
ctx.log("build ${ctx.buildId}: looking for scripts $scriptFiles in $scriptsDir/")
|
|
|
|
|
|
|
|
|
|
scriptFiles.forEach { script ->
|
|
|
|
|
val scriptFile = shFile(wsPath, script)
|
|
|
|
|
if (scriptFile.exists()) {
|
|
|
|
|
logger.info("build ${ctx.buildId}: found script $script, running it")
|
|
|
|
|
ctx.log("build ${ctx.buildId}: found script $script, running it")
|
|
|
|
|
|
|
|
|
|
ctx.logFile.append("\nRunning build file: $script\n")
|
|
|
|
|
ctx.log("Running build file: $script")
|
|
|
|
|
|
|
|
|
|
val scriptProcess = processes.builder(ctx.config, ctx.logFile, ctx.rev)
|
|
|
|
|
.command(scriptFile.absolutePath)
|
|
|
|
@ -95,11 +100,11 @@ class GitRunner(
|
|
|
|
|
handles.add(Handle(scriptProcess.toHandle(), ctx.buildId))
|
|
|
|
|
|
|
|
|
|
val ret = scriptProcess.waitFor()
|
|
|
|
|
logger.info("build ${ctx.buildId}: script $script returned $ret")
|
|
|
|
|
ctx.log("build ${ctx.buildId}: script $script returned $ret")
|
|
|
|
|
|
|
|
|
|
ctx.logFile.append("\n$script returned $ret\n")
|
|
|
|
|
ctx.log("$script returned $ret")
|
|
|
|
|
} else {
|
|
|
|
|
ctx.logFile.append("\nBuild file $scriptsDir/$script not found\n")
|
|
|
|
|
ctx.log("Build file $scriptsDir/$script not found")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -113,9 +118,16 @@ class GitRunner(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FailedToClone(
|
|
|
|
|
private val buildId: BuildId,
|
|
|
|
|
private val gitRepo: String
|
|
|
|
|
) : RuntimeException() {
|
|
|
|
|
override fun toString() =
|
|
|
|
|
"${this::class}: failed to clone $gitRepo for build id $buildId"
|
|
|
|
|
}
|
|
|
|
|
buildId: BuildId,
|
|
|
|
|
gitRepo: String
|
|
|
|
|
) : RuntimeException(
|
|
|
|
|
"${FailedToClone::class}: failed to clone $gitRepo for build id $buildId"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
class FailedToCheckout(
|
|
|
|
|
buildId: BuildId,
|
|
|
|
|
gitRepo: String,
|
|
|
|
|
rev: String
|
|
|
|
|
) : RuntimeException(
|
|
|
|
|
"failed to checkout revision $rev on repo $gitRepo for build id $buildId"
|
|
|
|
|
)
|
|
|
|
|