Reputation: 121
Any idea how I can query jenkins to get list of all jobs running specific GIT repo? Or list of all jobs and the GIT source code they are using?
Thanks,
Upvotes: 6
Views: 4417
Reputation: 121
This is how you get specific build # configuration using python: import json import urllib
url = 'http://jenkins_user:jenkins_password@my_jenkins_repo.com:8080/job/job_folder/job/job_name/build_number/api/json?pretty=true'
response = urllib.urlopen(url)
data = json.loads(response.read())
print data
with this you can first find all jobs under folder/repo, take last job for each and find the git repo for each job.
Upvotes: 0
Reputation: 21
import re
import jenkins
repo_name = 'my_repo'
found_jobs = []
server = jenkins.Jenkins(<jenkins-ip>, <username>, <password>)
jobs = server.get_all_jobs()
for job in jobs:
data = server.get_job_config(job['name']) . # data is xml
if re.search(r'%s\<\/url\>' %repo_name, data):
found_jobs.append(job['name'])
Basically, I'm just looking in the xml for the pattern: <url>my-repo-url</url>
and then appending to the list. For me, this was the easiest way without converting from xml to dict or json and then searching that data structure. Having searched hundreds of jobs, it has worked well for my case.
Upvotes: 2