Atlassian uses cookies to improve your browsing experience, perform analytics and research, and conduct advertising. Accept all cookies to indicate that you agree to our use of cookies on your device. Atlassian cookies and tracking notice, (opens new window)
#!/usr/bin/python
import requests
import string
import json
def get_projects(s):
projects = []
limit = 5
start = 0
is_last_page = False
while not is_last_page:
s.headers.update({'Content-Type': 'application/json'})
r = s.get('{}/rest/api/1.0/projects?limit={}&start={}'.format(bitbucket_url, limit, start))
data = r.json()
is_last_page = data['isLastPage']
if 'nextPageStart' in data:
start = data['nextPageStart']
for project in data['values']:
projects.append(project['key'])
return projects
def get_hook_settings(s, project_key):
r = s.get((hook_api + '/settings').format(bitbucket_url, project_key))
return r.json();
def update_hook_settings(s, project_key, config):
r = s.put((hook_api + '/enabled').format(bitbucket_url, project_key), json = config)
print r.status_code
print r.text
bitbucket_url = "http://localhost:7990/bitbucket"
hook_api = "{}/rest/api/latest/projects/{}/settings/hooks/com.nerdwin15.stash-stash-webhook-jenkins%3AjenkinsPostReceiveHook"
username = "admin"
password = "admin"
s = requests.Session()
s.auth = (username, password)
s.headers.update({'X-Atlassian-Token':'nocheck'})
s.headers.update({'Content-Type': 'application/json'})
for project in get_projects(s):
config = get_hook_settings(s, project)
config['jenkinsBase']='http://localhost:8080/jenkins'
update_hook_settings(s, project, config)
Parameter details
disabledEvents is a comma-separated list of class names of events to ignore. Supported class names are listed below, with links to the corresponding Bitbucket documentation explaining when each event is triggered: