From: Benjamin Drung Date: Tue, 28 Oct 2014 08:27:48 +0000 (+0100) Subject: Add webhook_post2querystring.py X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=d985954bf0afbf9102b851b5b70b303c9c6999a6;p=profitbricks%2Fjenkins-build-scripts.git Add webhook_post2querystring.py --- diff --git a/webhook_post2querystring.py b/webhook_post2querystring.py new file mode 100755 index 0000000..cd2156d --- /dev/null +++ b/webhook_post2querystring.py @@ -0,0 +1,44 @@ +#!/usr/bin/python + +# Copyright (C) 2014, ProfitBricks GmbH +# Authors: Benjamin Drung +# +# 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')