Skip to content

Instantly share code, notes, and snippets.

@offlinehacker
Created September 1, 2012 22:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save offlinehacker/3588862 to your computer and use it in GitHub Desktop.
Save offlinehacker/3588862 to your computer and use it in GitHub Desktop.
Jenkins script console shell client
#!/usr/bin/python
import re
import sys
import urllib
import urllib2
command=" ".join(sys.argv[1:])
srv="http://IP:8082/script"
script="def command = \"\"\""+command+"\"\"\"\ndef proc = command.execute()\nproc.waitFor()\nprintln \"stdout: ${proc.in.text}\""
data= urllib.urlencode({'script': script, 'json':'{"script": "' + script + '", "": "'+script+'"}', 'Submit': 'Run'})
u = urllib2.urlopen(srv, data)
lines= u.readlines()
a = re.compile(r'<pre>stdout: (.*?)<\/pre>', re.MULTILINE|re.DOTALL)
m = a.search(lines)
if m:
print m.group(1).strip().strip()
else:
print "command failed"
print lines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment