From fd01270b31d754e57efe1a41106e17015ed4eb3d Mon Sep 17 00:00:00 2001 From: gdunkle Date: Tue, 22 Oct 2013 16:21:12 -0400 Subject: [PATCH 1/4] include project name --- lib/build.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) mode change 100644 => 100755 lib/build.rb diff --git a/lib/build.rb b/lib/build.rb old mode 100644 new mode 100755 index 893e7f8..565347f --- a/lib/build.rb +++ b/lib/build.rb @@ -20,6 +20,7 @@ def initialize(data) @repo_url = data[:repo_url] @state = :waiting @before_sha = data[:before_sha] + @project_name = data[:project_name] end def run @@ -100,7 +101,7 @@ def command(cmd) @process.environment['CI_BUILD_BEFORE_SHA'] = @before_sha @process.environment['CI_BUILD_REF_NAME'] = @ref_name @process.environment['CI_BUILD_ID'] = @id - + @process.environment['CI_BUILD_PROJECT_NAME'] = @project_name @process.start @tmp_file_path = @tmp_file.path @@ -138,7 +139,7 @@ def checkout_cmd def clone_cmd cmd = [] cmd << "cd #{config.builds_dir}" - cmd << "git clone #{@repo_url} project-#{@project_id}" + cmd << "git clone #{@repo_url} #{project_dir}" cmd << "cd project-#{@project_id}" cmd << "git checkout #{@ref_name}" cmd.join(" && ") @@ -162,7 +163,7 @@ def config end def project_dir - File.join(config.builds_dir, "project-#{@project_id}") + File.join(config.builds_dir, "project-#{@project_id}/#{@project_name}") end end end From ed81ef426b5aaa201a2cd183dbce5816848c49e6 Mon Sep 17 00:00:00 2001 From: gdunkle Date: Wed, 23 Oct 2013 11:58:06 -0400 Subject: [PATCH 2/4] add some extra environment variables to make writing build scripts that require mutliple checkouts easier --- lib/build.rb | 19 +++++++++++++------ lib/network.rb | 3 ++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/build.rb b/lib/build.rb index 565347f..d582d69 100755 --- a/lib/build.rb +++ b/lib/build.rb @@ -4,6 +4,8 @@ require 'childprocess' require 'tempfile' require 'fileutils' +#require 'logger' + module GitlabCi class Build @@ -12,6 +14,8 @@ class Build attr_accessor :id, :commands, :ref, :tmp_file_path, :output, :state, :before_sha def initialize(data) + # log = Logger.new('log.txt') + # log.info "Data name is #{data}" @commands = data[:commands].to_a @ref = data[:ref] @ref_name = data[:ref_name] @@ -102,6 +106,9 @@ def command(cmd) @process.environment['CI_BUILD_REF_NAME'] = @ref_name @process.environment['CI_BUILD_ID'] = @id @process.environment['CI_BUILD_PROJECT_NAME'] = @project_name + @process.environment['CI_BUILD_DIR'] = config.builds_dir + @process.environment['CI_BUILD_PROJECT_DIR'] = project_dir + @process.start @tmp_file_path = @tmp_file.path @@ -130,7 +137,7 @@ def command(cmd) def checkout_cmd cmd = [] - cmd << "cd #{project_dir}" + cmd << "cd #{project_dir}/#{@project_name}" cmd << "git reset --hard" cmd << "git checkout #{@ref}" cmd.join(" && ") @@ -139,15 +146,15 @@ def checkout_cmd def clone_cmd cmd = [] cmd << "cd #{config.builds_dir}" - cmd << "git clone #{@repo_url} #{project_dir}" - cmd << "cd project-#{@project_id}" + cmd << "git clone #{@repo_url} #{project_dir}/#{@project_name}" + cmd << "cd #{project_dir}/#{@project_name}" cmd << "git checkout #{@ref_name}" cmd.join(" && ") end def fetch_cmd cmd = [] - cmd << "cd #{project_dir}" + cmd << "cd #{project_dir}/#{@project_name}" cmd << "git reset --hard" cmd << "git clean -f" cmd << "git fetch" @@ -155,7 +162,7 @@ def fetch_cmd end def repo_exists? - File.exists?(File.join(project_dir, '.git')) + File.exists?(File.join("#{project_dir}/#{@project_name}", '.git')) end def config @@ -163,7 +170,7 @@ def config end def project_dir - File.join(config.builds_dir, "project-#{@project_id}/#{@project_name}") + File.join(config.builds_dir, "project-#{@project_id}") end end end diff --git a/lib/network.rb b/lib/network.rb index 880c47d..f09698d 100644 --- a/lib/network.rb +++ b/lib/network.rb @@ -35,7 +35,8 @@ def get_build repo_url: response['repo_url'], ref: response['sha'], ref_name: response['ref'], - before_sha: response['before_sha'] + before_sha: response['before_sha'], + project_name: response['project_name'] } elsif response.code == 403 puts 'forbidden' From 39e1b046f56bb3fe95f616903eaf8e29e5e59837 Mon Sep 17 00:00:00 2001 From: gdunkle Date: Wed, 23 Oct 2013 12:08:28 -0400 Subject: [PATCH 3/4] remove test logging stuff --- lib/build.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/build.rb b/lib/build.rb index d582d69..e82c126 100755 --- a/lib/build.rb +++ b/lib/build.rb @@ -4,7 +4,6 @@ require 'childprocess' require 'tempfile' require 'fileutils' -#require 'logger' module GitlabCi @@ -14,8 +13,6 @@ class Build attr_accessor :id, :commands, :ref, :tmp_file_path, :output, :state, :before_sha def initialize(data) - # log = Logger.new('log.txt') - # log.info "Data name is #{data}" @commands = data[:commands].to_a @ref = data[:ref] @ref_name = data[:ref_name] From dd874104a45f9eb4b869173454a60fab0c7ba175 Mon Sep 17 00:00:00 2001 From: gdunkle Date: Wed, 23 Oct 2013 14:28:55 -0400 Subject: [PATCH 4/4] add more enviroment variables --- lib/build.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/build.rb b/lib/build.rb index e82c126..991db9a 100755 --- a/lib/build.rb +++ b/lib/build.rb @@ -103,6 +103,7 @@ def command(cmd) @process.environment['CI_BUILD_REF_NAME'] = @ref_name @process.environment['CI_BUILD_ID'] = @id @process.environment['CI_BUILD_PROJECT_NAME'] = @project_name + @process.environment['CI_BUILD_PROJECT_ID'] = @project_id @process.environment['CI_BUILD_DIR'] = config.builds_dir @process.environment['CI_BUILD_PROJECT_DIR'] = project_dir