diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2012-10-05 13:04:22 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2012-10-05 13:04:22 +0300 |
commit | f13422976258dbcc6ccf6dffb54d7b76ecdb89f9 (patch) | |
tree | 94dfd6251f6098bcc700bd08be2f5b3cd0eed05b /lib | |
parent | 4fd1b9c54647deedcf25cc9eedf887b302f4d025 (diff) | |
download | gitlab-ci-f13422976258dbcc6ccf6dffb54d7b76ecdb89f9.tar.gz |
Cleanup & create build in application
Diffstat (limited to 'lib')
-rw-r--r-- | lib/project.rb | 12 | ||||
-rw-r--r-- | lib/runner.rb | 25 |
2 files changed, 25 insertions, 12 deletions
diff --git a/lib/project.rb b/lib/project.rb index 0949c81..962b3c5 100644 --- a/lib/project.rb +++ b/lib/project.rb @@ -7,6 +7,18 @@ class Project < ActiveRecord::Base has_many :builds + def register_build opts={} + default_opts = { + project_id: self.id, + status: 'runing' + } + + allowed_opts = {} + allowed_opts[:commit_ref] = opts[:after] + + @build = Build.create(default_opts.merge!(allowed_opts)) + end + def status if last_build last_build.status diff --git a/lib/runner.rb b/lib/runner.rb index 63fb5da..ba5a213 100644 --- a/lib/runner.rb +++ b/lib/runner.rb @@ -2,28 +2,29 @@ class Runner attr_accessor :project, :build @queue = :runner - def self.perform(project_id) - new(Project.find(project_id)).run + def self.perform(build_id) + new(Build.find(build_id)).run end - def initialize(project) - @project = project + def initialize(build) + @build = build + @project = build.project end def run - @build = Build.create( - project_id: project.id, - status: 'runing' - ) - trace = '' path = project.path - project.scripts.each_line do |line| + commands = project.scripts + commands.each_line do |line| + line = line.strip + trace << "\n" cmd = "cd #{path} && " + line + trace << cmd + trace << "\n" trace << `#{cmd}` unless $?.exitstatus == 0 - @build.update_attributes( + build.update_attributes( trace: trace, status: 'fail' ) @@ -32,7 +33,7 @@ class Runner end end - @build.update_attributes( + build.update_attributes( trace: trace, status: 'success' ) |