-
Notifications
You must be signed in to change notification settings - Fork 0
/
jenkinsjob.py
47 lines (35 loc) · 1.6 KB
/
jenkinsjob.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import logging
import requests
from jenkinsapi.jenkins import Jenkins
from jenkinsapi.utils.crumb_requester import CrumbRequester
from propertyreader import Properties
properties = Properties()
if properties.logslevel.level == 'INFO':
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s %(name)s - %(levelname)s - %(message)s')
if properties.logslevel.level == 'DEBUG':
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s %(name)s - %(levelname)s - %(message)s')
class InstallerJob(object):
def install(self, **kwargs):
self.url = properties.jenkinsInstaller.jenkins_url
self.jobName = properties.jenkinsInstaller.jenkins_jobname
requests.packages.urllib3.disable_warnings()
logging.info("Talking to Jenkins now.")
connectJenkin = Jenkins(self.url,
requester=CrumbRequester(baseurl=self.url, ssl_verify=False))
job = connectJenkin[self.jobName]
query = job.invoke(build_params=kwargs)
logging.info("{} job has been successfully submitted.".format(query.get_job_name()))
if query.is_queued() or query.is_running():
query.block_until_complete(delay=30)
build = query.get_build()
if build.get_status() == 'SUCCESS':
logging.info("{} job has been completed.".format(build))
return 'SUCCESS'
else:
logging.info("{} job has been completed with result {}, for more details go at {}"
.format(build, build.get_status(), build.get_result_url()))
return 'FAILURE'