Skip to content

Instantly share code, notes, and snippets.

@electrum
Created November 7, 2012 23:09
Show Gist options
  • Save electrum/4035227 to your computer and use it in GitHub Desktop.
Save electrum/4035227 to your computer and use it in GitHub Desktop.
GIT_SSH wrapper for Jenkins and GitHub
#!/usr/bin/env python
import re, os, os.path, sys
HOST = '[email protected]'
KEYS = '/data/users/jenkins/home/.ssh'
if len(sys.argv) != 3:
sys.stderr.write('usage: git-ssh host command\n')
sys.exit(100)
host = sys.argv[1]
command = sys.argv[2]
if host != HOST:
sys.stderr.write('unsupported host: %s\n' % host)
sys.exit(100)
pattern = r'\'([A-Za-z0-9-]+)/([A-Za-z0-9-]+)\.git\''
r = re.search(pattern, command)
if r is None:
sys.stderr.write('repository not found in command: %s\n' % command)
sys.exit(100)
username, repo = r.groups()
identity = os.path.join(KEYS, username, repo)
os.execlp('ssh', 'ssh', '-i', identity, host, command)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment