Sumit Kumar Rai
07/01/2021, 12:09 PMSpencer
07/01/2021, 1:05 PMgit
. I've done this by using ShellTasks
that run git clone
and other such git
commands as needed.
You'll have to handle the authentication (username/pass or ssh key in a Secret
). I used ssh authentication by extending ShellTask
to take a private_ssh_key
which writes it to a local file before using it in the git
command by setting the GIT_SSH_COMMAND
environment variable for the ShellTask.run
Something like:
class CloneTask(ShellTask):
...
def run(self, repo=None, private_ssh_key=None, **kwargs):
command = f"git clone {repo}"
if private_ssh_key:
with tempfile.NamedTemporaryFile('w') as k:
k.write(private_ssh_key)
k.flush()
env = kwargs.pop("env", {})
env["GIT_SSH_COMMAND"] = f"ssh -i {k.name}"
return super().run(command=command, env=env, **kwargs)
return super().run(command=command, **kwargs)
Kevin Kho