def checkout(self): # Git checkout implementation. self.build.append_message("----------\nCloning repository...") # TODO: may need to make SSH options more configurable, possibly using settings file? answer_file = None ask_pass = "" key_mgmt = dict() if self.repo.startswith("http://") or self.repo.startswith("https://"): # if using a http repo and a scm login password is set, tell git to execute # a file to retrieve the password if self.project.scm_login and self.project.scm_login.password is not None: answer_file = commands.answer_file( self.project.scm_login.get_password()) ask_pass = "******"bash %s\"" % answer_file else: # it's not set, we can avoid an error if it asks for a password and # we have ALREADY added the username to the URL if we could, but if not # there's a slim chance this could go interactive on OS X laptops. See # development setup docs for how to turn this off. ask_pass = "******" else: # if using SSH, there's a chance we haven't seen the repo before, and need to be cool about it. # TODO: we may allow people to turn this off by adding this as a setting default. key_mgmt = { "GIT_SSH_COMMAND": "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no", } if not self.project.ssh_keys.count(): raise Exception( "add one or more SSH keys to the project or use a http:// or https:// URL" ) branch_spec = "" if self.project.repo_branch: branch_spec = "-b %s --single-branch " % shlex.quote( self.project.repo_branch) try: # run it cmd = "git clone %s%s %s%s -v" % (branch_spec, shlex.quote(self.repo), self.build.working_dir, ask_pass) # we should be a BIT smarter than this, but for now use the timeout command to kill the build if the SSH # unlock password or something might be wrong. We can modifiy this later to have watch phrases # that kill the command automatically when we see certain output. output = commands.execute_command(self.build, cmd, output_log=False, message_log=True, timeout=600, env=key_mgmt) finally: # delete the answer file if we had one if answer_file: os.remove(answer_file) return output
def clone_repo(self, organization, build, repo, count): # much of code is borrowed from plugins.scm.git - but adapted enough that # sharing is probably not worthwhile. For instance, this doesn't have # to deal with SSH checkouts. build.append_message("cloning repo...") repo = self.fix_scm_url(repo, organization.scm_login.username) answer_file = commands.answer_file(organization.scm_login.get_password()) ask_pass = "******"bash %s\"" % answer_file # TODO: add --depth 1 to git.py checkouts as well branch_spec = "--depth 1 --single-branch " clone_path = os.path.join(build.working_dir, str(count)) try: # run it cmd = "git clone %s %s %s %s" % (shlex.quote(repo), clone_path, ask_pass, branch_spec) output = commands.execute_command(build, cmd, output_log=False, message_log=True) finally: # delete the answer file if we had one os.remove(answer_file) return clone_path