This repository is currently being migrated. It's locked while the migration is in progress.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpyjenkins.py
139 lines (114 loc) · 4.15 KB
/
pyjenkins.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
from com.tanium.python import PyJenkinsBuild, BuildResultException
from com.tanium.util import JenkinsHelper
from hudson import AbortException
from hudson.model import Result
from jenkins.model import Jenkins
context = None
shared_context = None
config = None
build = None
launcher = None
listener = None
logger = None
env_vars = None
review_build = False
def init(new_context, new_config):
assert new_context is not None
assert new_config is not None
global context, shared_context, config, build, launcher, listener, logger, env_vars
context = new_context
shared_context = new_context.sharedContext
config = new_config
build = context.build
launcher = context.launcher
listener = context.listener
logger = listener.getLogger()
env_vars = JenkinsHelper.getEnvVars(context)
logger.println("pyjenkins module initialized!")
return True
def register_pybuild(pybuild):
assert context is not None
logger.println("Registering pyjenkins build")
context.pybuild = pybuild
def report_tests(test_file_pattern):
return JenkinsHelper.reportTests(context, test_file_pattern)
def archive_artifacts(source_patterns):
JenkinsHelper.archiveArtifacts(context, source_patterns)
def execute(cmds):
return JenkinsHelper.execute(context, cmds, env_vars)
def execute_or_fail(cmds):
result = execute(cmds)
if not result:
listener.fatalError("Command failed: " + str(cmds))
raise BuildResultException(Result.FAILURE)
def is_windows():
return JenkinsHelper.isNodeWindows(context)
def remote_file(relative_path):
return JenkinsHelper.getRemoteFile(context, relative_path)
def read_remote_file(relative_path):
return remote_file(relative_path).readToString()
def env(var):
return env_vars.get(var)
def env_set(var, value):
if value is None:
env_vars.remove(var)
else:
env_vars.put(var, value)
def ensure_has_plugin(plugin_name):
if Jenkins.getInstance().getPlugin(plugin_name) is None:
raise AbortException("Plugin '" + plugin_name + "' is not installed!")
def trigger_job(job_name, params=None):
return JenkinsHelper.triggerJob(context, job_name, params)
def trigger_jobs(job_names, params=None):
return JenkinsHelper.triggerJobs(context, job_names, params)
def trigger_job_and_wait(job_name, params=None, wait_millis=0):
return JenkinsHelper.triggerJobAndWait(context, job_name, params, wait_millis)
def trigger_jobs_and_wait(job_names, params=None, wait_millis=0):
return JenkinsHelper.triggerJobsAndWait(context, job_names, params, wait_millis)
def wait_for_job_start(job, wait_millis=0):
return JenkinsHelper.waitForJobToStart(context, job, wait_millis)
def wait_for_jobs_start(jobs, wait_millis=0):
return JenkinsHelper.waitForJobsToStart(context, jobs, wait_millis)
def wait_for_job(job, wait_millis=0):
return JenkinsHelper.waitForJob(context, job, wait_millis)
def wait_for_jobs(jobs, wait_millis=0):
if isinstance(jobs, list):
return JenkinsHelper.waitForJobsList(context, jobs, wait_millis)
else:
return JenkinsHelper.waitForJobs(context, jobs, wait_millis)
def run_git(args, with_auth=False):
return JenkinsHelper.runGit(context, args, env_vars, with_auth)
def is_pull_request_build():
return config.pullRequestBuild == True
def is_release_build():
return config.releaseBuild == True
__all__ = [ "PyJenkinsBuild",
"Result",
"build",
"launcher",
"listener",
"logger",
"register_pybuild",
"report_tests",
"archive_artifacts",
"execute",
"execute_or_fail",
"is_windows",
"remote_file",
"read_remote_file",
"env",
"env_set",
"ensure_has_plugin",
"trigger_job",
"trigger_jobs",
"trigger_job_and_wait",
"trigger_jobs_and_wait",
"wait_for_job_start",
"wait_for_jobs_start",
"wait_for_job",
"wait_for_jobs",
"run_git",
"is_pull_request_build",
"is_release_build",
"shared_context",
]