Last active
December 28, 2015 18:09
-
-
Save jadar/7540689 to your computer and use it in GitHub Desktop.
This gist is a Python script that will perform an HTTP POST to a server with data from Jenkins and a Maven Project. Kinda hard coded but whatever. Replace values that have an asterisk in front of them with your own.
This file contains 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/python | |
import os | |
import httplib | |
import urllib | |
import xml.sax | |
workspace = os.environ.get('WORKSPACE') | |
# data to send to sever | |
commit = os.environ.get('GIT_COMMIT') | |
buildNumber = os.environ.get('BUILD_NUMBER') | |
version = os.environ.get('POM_VERSION') | |
platform = "None" | |
fileName = "None" | |
# find version from maven project | |
class FindVersion(xml.sax.ContentHandler): | |
read = False | |
finalContent = "" | |
def startElement(self, name, attrs): | |
if name == "version": | |
if not self.finalContent: | |
self.read = True | |
def characters(self, content): | |
#print self.read | |
if self.read == True: | |
self.finalContent += content | |
def endElement(self, name): | |
if name == "version" and self.read: | |
self.read = False | |
global version | |
version = self.finalContent | |
# catches exception | |
try: | |
xmlParser = xml.sax.make_parser() | |
xmlParser.setContentHandler(FindVersion()) | |
xmlParser.parse(open(workspace + "*POM_LOCATION", "r")) | |
except: | |
pass | |
# find files and POST to server | |
for root, dirs, files in os.walk(workspace): | |
for file in files: | |
if not(file.startswith("original")) and ("*FILENAME" in file) and file.endswith(".jar"): | |
if "bukkit" in file: | |
platform = "bukkit" | |
else: | |
if "forge" in file: | |
platform = "forge" | |
fileName = file | |
# concatenate POST data | |
params = urllib.urlencode({'*example1': value1, '*example2': value2}) | |
headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"} | |
connection = httplib.HTTPConnection("*YOUR-DOMAIN") | |
connection.request("POST", "*YOUR-PATH", params, headers) | |
response = connection.getresponse() | |
print response.status, response.reason | |
print response.read() | |
connection.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment