summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xGitAutoDeploy.py44
-rw-r--r--docs/Configuration.md52
2 files changed, 61 insertions, 35 deletions
diff --git a/GitAutoDeploy.py b/GitAutoDeploy.py
index c1d98ca..fd4e193 100755
--- a/GitAutoDeploy.py
+++ b/GitAutoDeploy.py
@@ -171,7 +171,7 @@ class WebhookRequestHandler(BaseHTTPRequestHandler):
from threading import Timer
# Extract repository URL(s) from incoming request body
- repo_urls, ref, action = self.get_repo_params_from_request()
+ repo_urls, ref, action, data = self.get_repo_params_from_request()
self.send_response(200)
self.send_header('Content-type', 'text/plain')
self.end_headers()
@@ -179,7 +179,8 @@ class WebhookRequestHandler(BaseHTTPRequestHandler):
# Wait one second before we do git pull (why?)
Timer(1.0, GitAutoDeploy.process_repo_urls, (repo_urls,
ref,
- action)).start()
+ action,
+ data)).start()
def log_message(self, format, *args):
"""Overloads the default message logging method to allow messages to
@@ -320,7 +321,7 @@ class WebhookRequestHandler(BaseHTTPRequestHandler):
logger.error("ERROR - Unable to recognize request origin. Don't know how to handle the request.")
logger.info("Event details - ref: %s; action: %s" % (ref or "master", action))
- return repo_urls, ref or "master", action
+ return repo_urls, ref or "master", action, data
# Used to describe when a filter does not match a request
@@ -394,7 +395,7 @@ class GitAutoDeploy(object):
return mpid
@staticmethod
- def process_repo_urls(urls, ref, action):
+ def process_repo_urls(urls, ref, action, data):
import os
import time
import logging
@@ -413,36 +414,23 @@ class GitAutoDeploy(object):
try:
# Verify that all filters matches the request (if any filters are specified)
if 'filters' in repo_config:
- for filter in repo_config['filters']:
-
- # Filter with both action and ref?
- if 'action' in filter and 'ref' in filter:
-
- if filter['action'] == action and filter['ref'] == ref:
- # This filter is a match, OK to proceed
- continue
-
- raise FilterMatchError()
+ filter_matched = True;
- # Filter with only action?
- if 'action' in filter:
+ # at least one filter must match
+ for filter in repo_config['filters']:
- if filter['action'] == action:
- # This filter is a match, OK to proceed
+ # all options specified in the filter must match
+ for filter_key, filter_value in filter.iteritems():
+ # support for earlier version so it's non-breaking functionality.
+ if filter_key == 'action' and filter_value == action:
continue
- raise FilterMatchError()
-
- # Filter with only ref?
- if 'ref' in filter:
-
- if filter['ref'] == ref:
- # This filter is a match, OK to proceed
+ if filter_key not in data or filter_value != data[filter_key]:
+ filter_matched = False
continue
- raise FilterMatchError()
-
- # Filter does not match, do not process this repo config
+ if not filter_matched:
+ logger.info ("No filter matched")
raise FilterMatchError()
except FilterMatchError as e:
diff --git a/docs/Configuration.md b/docs/Configuration.md
index c1be297..b911048 100644
--- a/docs/Configuration.md
+++ b/docs/Configuration.md
@@ -32,14 +32,25 @@ Repository configurations are comprised of the following elements:
With filter, it is possible to trigger the deploy only if the criteria are met.
For example, deploy on `push` to the `master` branch only, ignore other branches.
-Filters are defined by providing an `action` and/or a `ref` element (most the
-time both would be used in the filter )
+Filters are defined by providing keys/values to be looked up in the original
+data sent by the web hook.
-A special filter syntax also exist to take care of GitHub pull-requests. See
-[Continuous Delivery via Pull requests](./Continuous Delivery via Pull requests.md)
-for details on how it works.
+For example, GitLab web hook data looks like this:
+
+```json
+ {
+ "object_kind":"build",
+ "ref":"master",
+ "tag":false,
+ ...
+ }
+```
+
+A filter can use `object_kind` and `ref` attributes for example to execute the
+deploy action only on a `build` event on the `master` branch.
# Examples
+*(Note: the filter examples below are valid for GitLab)*
Execute pre-deploy script, don't `pull` the repository but execute a deploy
script, and finish with a post-deploy script. Execute only for `push` events on
@@ -60,7 +71,7 @@ the `master` branch.
"deploy": "echo deploying",
"filters": [
{
- "action": "push",
+ "object_kind": "push",
"ref": "refs/heads/master"
}
]
@@ -84,11 +95,38 @@ Clone repository on `push` to `master`.
"path": "~/repositories/hooktest",
"filters": [
{
- "action": "push",
+ "object_kind": "push",
"ref": "refs/heads/master"
}
]
}
]
}
+```
+
+Execute script upon GitLab CI successful build of `master` branch.
+
+```json
+{
+ "pidfilepath": "~/.gitautodeploy.pid",
+ "host": "0.0.0.0",
+ "port": 8080,
+ "global_deploy": [
+ "echo Pre-deploy script",
+ "echo Post-deploy script"
+ ],
+ "repositories": [
+ {
+ "url": "http://gitlab/playground/hooktest.git",
+ "deploy": "echo deploying project!",
+ "filters": [
+ {
+ "object_kind": "build",
+ "ref": "master",
+ "build_status": "success"
+ }
+ ]
+ }
+ ]
+}
``` \ No newline at end of file