Created
July 22, 2015 16:11
-
-
Save jpic/4033ab582b241a8a02cb 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 | |
''' | |
export JENKINS_BUILD_COMMAND="java -jar /var/cache/jenkins/war/WEB-INF/jenkins-cli.jar -s http://localhost:8080 build" | |
export GITHUB_USERNAME=youruser | |
export CRAZY_JENKINS=owner/repo:job1*3,job2*1 | |
# Note the space here, for the token not to be stored in bash history | |
GITHUB_TOKEN=yourtoken crazy_jenkins.py | |
''' | |
import os | |
import github | |
gh = github.GitHub( | |
username=os.environ.get('GITHUB_USERNAME', None), | |
access_token=os.environ.get('GITHUB_TOKEN', None) or None, | |
password=os.environ.get('GITHUB_PASSWORD', None)) | |
build = os.environ.get('JENKINS_BUILD_COMMAND') | |
for repository in os.environ.get('CRAZY_JENKINS').split(' '): | |
gh_config, jenkins_config = repository.split(':') | |
owner, repo = gh_config.split('/') | |
jobs = jenkins_config.split(',') | |
pulls = gh.repos(owner)(repo).pulls.get() | |
for pull in pulls: | |
branch = pull['head']['ref'] | |
sha = pull['head']['sha'] | |
for job in jobs: | |
job_name, min_success = job.split('*') | |
successes = 0 | |
for state in gh.repos(owner)(repo).statuses(sha).get(): | |
if state == 'success': | |
successes += 1 | |
if successes <= min_success: | |
os.system('%s %s -p BRANCH=%s' % (build, job, branch)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment