Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smbambling/73b216511f89b0deb6f897282f1352d6 to your computer and use it in GitHub Desktop.
Save smbambling/73b216511f89b0deb6f897282f1352d6 to your computer and use it in GitHub Desktop.
#!/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