]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
Add webhook_post2querystring.py
authorBenjamin Drung <benjamin.drung@profitbricks.com>
Tue, 28 Oct 2014 08:27:48 +0000 (09:27 +0100)
committerBenjamin Drung <benjamin.drung@profitbricks.com>
Tue, 28 Oct 2014 08:27:48 +0000 (09:27 +0100)
webhook_post2querystring.py [new file with mode: 0755]

diff --git a/webhook_post2querystring.py b/webhook_post2querystring.py
new file mode 100755 (executable)
index 0000000..cd2156d
--- /dev/null
@@ -0,0 +1,44 @@
+#!/usr/bin/python
+
+# Copyright (C) 2014, ProfitBricks GmbH
+# Authors: Benjamin Drung <benjamin.drung@profitbricks.com>
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+import logging
+import os
+
+import flask
+import jenkins
+
+JENKINS_URL = "https://jenkins/"
+JENKINS_JOB = "gitlab_integration"
+JENKINS_JOB_TOKEN = "gitlab"
+_LOG_LEVEL = logging.INFO
+_LOG_FORMAT = '%(asctime)s %(name)s [%(process)d] %(levelname)s: %(message)s'
+
+app = flask.Flask(__name__)
+logging.basicConfig(format=_LOG_FORMAT, level=_LOG_LEVEL)
+logger = logging.getLogger(os.path.basename(__file__))
+
+
+@app.route('/', methods=['POST'])
+def receive_gitlab_webhook():
+    logger.info("Received push event:\n{event}".format(event=flask.request.data))
+    jenkins_client = jenkins.Jenkins(JENKINS_URL, None, None)
+    logger.info("Sending payload to {url}job/{job} ...".format(url=JENKINS_URL, job=JENKINS_JOB))
+    jenkins_client.build_job(JENKINS_JOB, {'payload': flask.request.data}, JENKINS_JOB_TOKEN)
+    return "OK"
+
+if __name__ == '__main__':
+    app.run(host='0.0.0.0')