Skip to content
This repository has been archived by the owner on May 12, 2018. It is now read-only.

Checkout projects into project-id/project_name subdirectory #49

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions lib/build.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require 'fileutils'
require 'bundler'


module GitlabCi
class Build
TIMEOUT = 7200
Expand All @@ -21,6 +22,7 @@ def initialize(data)
@repo_url = data[:repo_url]
@state = :waiting
@before_sha = data[:before_sha]
@project_name = data[:project_name]
@timeout = data[:timeout] || TIMEOUT
@allow_git_fetch = data[:allow_git_fetch]
end
Expand Down Expand Up @@ -102,7 +104,11 @@ 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.environment['CI_BUILD_PROJECT_ID'] = @project_id
@process.environment['CI_BUILD_DIR'] = config.builds_dir
@process.environment['CI_BUILD_PROJECT_DIR'] = project_dir

@process.start

@tmp_file_path = @tmp_file.path
Expand Down Expand Up @@ -131,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(" && ")
Expand All @@ -140,15 +146,16 @@ def checkout_cmd
def clone_cmd
cmd = []
cmd << "cd #{config.builds_dir}"
cmd << "git clone #{@repo_url} project-#{@project_id}"
cmd << "cd project-#{@project_id}"
cmd << "git checkout #{@ref}"

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 -fdx"
cmd << "git remote set-url origin #{@repo_url}"
Expand All @@ -157,7 +164,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
Expand Down
1 change: 1 addition & 0 deletions lib/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def get_build
ref: response['sha'],
ref_name: response['ref'],
before_sha: response['before_sha'],
project_name: response['project_name']
allow_git_fetch: response['allow_git_fetch'],
timeout: response['timeout']
}
Expand Down