Created
November 7, 2012 23:09
-
-
Save electrum/4035227 to your computer and use it in GitHub Desktop.
GIT_SSH wrapper for Jenkins and GitHub
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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