Skip to content

Instantly share code, notes, and snippets.

Created April 24, 2018 11:54
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
#/usr/bin/env python
import json
import os
import sys
import requests
from requests.auth import HTTPBasicAuth is used to easily update the jenkins hook for all repositories
#multiple projects can be passed in as a comma separated list
#An example of running this is below
#python bbUsername bbPassword bbRepo http://your-host-name:2500/jenkins
bitbuckerUsername = sys.argv[1];
bitbucketPassword = sys.argv[2];
projectNamesList = str(sys.argv[3]).split(",");
newJenkinsBase = sys.argv[4]
bitbucketInstance = sys.argv[5]
for project in projectNamesList:
r = requests.get(bitbucketInstance + project + "/repos?size=100&limit=100", auth=HTTPBasicAuth(bitbuckerUsername, bitbucketPassword))
jsonResponse = r.json();
for value in jsonResponse["values"]:
repoName = value["name"].lower()
uri = bitbucketInstance + project.lower() + "/repos/" + repoName + "/settings/hooks/com.nerdwin15.stash-stash-webhook-jenkins:jenkinsPostReceiveHook/settings"
hookresp = requests.get(uri, auth=HTTPBasicAuth(sys.argv[1], sys.argv[2]))
if(200 == hookresp.status_code):
newBody = (hookresp.json())
newBody["jenkinsBase"] = newJenkinsBase
hookresp = requests.put(uri, json=newBody, auth=HTTPBasicAuth(sys.argv[1], sys.argv[2]))
if(200 == hookresp.status_code):
print("Succesfully updated the hook for " + repoName);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment