Advertisement
Guest User

Untitled

a guest
May 9th, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import os
  4. from elasticsearch import Elasticsearch
  5. import jenkins
  6.  
  7. # change to your here
  8. jenkinsUrl = "http://localhost:8080"
  9. elasticUrl = "http://localhost:9200"
  10.  
  11. #server = jenkins.Jenkins(jenkinsUrl)
  12. server = jenkins.Jenkins(jenkinsUrl, username='myuser', password='mypassword')
  13. es = Elasticsearch([elasticUrl])
  14. env = os.environ
  15. body = env.data
  16. print body
  17. jobs = server.get_jobs()
  18. for job in jobs:
  19. jobname = job['fullname']
  20. buildinfo = server.get_job_info(job['name'])
  21. buildnumber = buildinfo['lastCompletedBuild']['number']
  22. body['JOB_NAME'] = jobname
  23. body['JOB_URL'] = job['url']
  24. body['BUILD_DISPLAY_NAME'] = "#" + str(buildnumber)
  25. body['BUILD_ID'] = buildnumber
  26. body['BUILD_NUMBER'] = buildnumber
  27. res = es.index(index="jenkins_env", doc_type='env', id=job['name'], body=body)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement