Created
April 24, 2018 11:54
-
-
Save thrownullpointer/699e854fd16e8cfcddbcb10a0f428c72 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 | |
import json | |
import os | |
import sys | |
import requests | |
from requests.auth import HTTPBasicAuth | |
#jenkinsHookUpdate.py 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 jenkinsHookUpdate.py bbUsername bbPassword bbRepo http://your-host-name:2500/jenkins https://your-host.com/rest/api/1.0/projects/ | |
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