WebHook broker that accepts notifications from multiple platforms and performs simple actions in response
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

jenkins.py 982B

123456789101112131415161718192021222324252627282930
  1. import jenkins
  2. from bs4 import BeautifulSoup
  3. from .service import Service
  4. class Jenkins(Service):
  5. SCM_CLASS = "hudson.plugins.git.GitSCM"
  6. def __init__(self, url, username, password):
  7. super().__init__("jenkins")
  8. self._server = jenkins.Jenkins(url, username=username, password=password)
  9. self._jobs = []
  10. def refresh(self):
  11. self._jobs = list(self._get_jobs())
  12. def _get_jobs(self):
  13. for job in self._server.get_all_jobs():
  14. name = job["fullname"]
  15. config = BeautifulSoup(self._server.get_job_config(name), features="xml")
  16. for git_config in config.find_all("scm", class_=self.SCM_CLASS):
  17. branch_spec = git_config.find("branches").find("name").text
  18. yield name, branch_spec, git_config.find("url").text
  19. def build_job_by_scm_url(self, urls):
  20. for job, branch, url in self._jobs:
  21. if url in urls:
  22. self._server.build_job(job)