lib/evrone/ci/worker/middlewares/docker_script.rb in evrone-ci-worker-0.2.0.pre0 vs lib/evrone/ci/worker/middlewares/docker_script.rb in evrone-ci-worker-0.2.0.pre1

- old
+ new

@@ -12,24 +12,46 @@ if env.ssh && env.docker_repo_dir code = run_script(env) if code == 0 app.call env else - code + case read_state(env) + when "script" + code + else + code * -1 + end end else app.call env end end private def run_script(env) scp = ::Net::SCP.new(env.ssh.connection) - script = [env.docker_repo_dir, ".ci_script.sh"].join("/") - puts env.job.message.script.inspect - scp.upload! StringIO.new(env.job.message.script), script - env.ssh.spawn "env - bash #{script}", chdir: env.docker_repo_dir, &env.job.method(:add_to_output) + script = [env.docker_repo_dir, ".ci_build.sh"].join("/") + scp.upload! StringIO.new(content(env)), script + env.ssh.spawn "env - HOME=$HOME bash #{script}", chdir: env.docker_repo_dir, &env.job.method(:add_to_output) + end + + def content(env) + buf = ["set -e"] + buf << "echo before_script > #{env.docker_repo_dir}/.ci_state" + buf << env.job.message.before_script + buf << "echo script > #{env.docker_repo_dir}/.ci_state" + buf << env.job.message.script + buf.join("\n") + end + + def read_state(env) + buf = "" + state_file = env.docker_repo_dir.join(".ci_state") + env.ssh.spawn "cat #{state_file}" do |out| + buf << out + end + buf.strip end end end end