Created
May 29, 2016 13:35
-
-
Save smbambling/73b216511f89b0deb6f897282f1352d6 to your computer and use it in GitHub Desktop.
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/env python | |
# This git-hook triggers the Code-Manager per branch and checks for status to be returned | |
# Requirements: This requires the python request module ( sudo yum install python-requests ) | |
import requests | |
from requests.packages.urllib3.exceptions import InsecureRequestWarning | |
requests.packages.urllib3.disable_warnings(InsecureRequestWarning) | |
import json | |
import sys | |
for line in sys.stdin: | |
(oldrev, newrev, refname) = line.split() | |
branch = refname.split('/')[2] | |
url = 'https://<your_hostname>:8170/code-manager/v1/webhook?type=stash' | |
# Deploy ALL Branches | |
#data = '{"deploy-all": true, "wait": true}' | |
# Deploy Specific Branch | |
data = '{ "refChanges": [{"refId":"refs/heads/%s"}] }' % branch | |
headers = {'Content-Type': 'application/json'} | |
r = requests.post(url, headers=headers, data=data, verify=False, timeout=(4, 15)) | |
if r.status_code == 200: | |
print '\nCode-Manger deployment triggered for environment %s \n' % branch | |
else: | |
print 'API Request Failure' | |
print 'Status Code: ', r.status_code | |
print 'Return Reason: ', r.text | |
sys.exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment