-
Notifications
You must be signed in to change notification settings - Fork 0
/
job.py
49 lines (43 loc) · 1.91 KB
/
job.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
"""
Utilities for working with Jenkins jobs.
"""
import urllib
import requests
from utils import log
class Job:
"""Utilities for working with Jenkins jobs."""
@log
def create_pipeline_job(self, **kwargs):
"""Creates a pipeline job for a repo."""
bitbucket = kwargs.get('bitbucket')
jenkins = kwargs.get('jenkins')
url = f"http://{jenkins.get('host')}/job/pipeline-seed-job/buildWithParameters?"
url += f"project={bitbucket.get('repo')}&scmUrl=http://{bitbucket.get('host')}"
url += f"/scm/{bitbucket.get('project')}/{bitbucket.get('repo')}.git"
return requests.request(
'POST', url, headers=kwargs.get('default_headers'))
@log
def delete_pipeline_job(self, **kwargs):
"""Deletes a pipeline job for a repo."""
bitbucket = kwargs.get('bitbucket')
jenkins = kwargs.get('jenkins')
url = f"http://{jenkins.get('host')}/job/{bitbucket.get('repo')}-build/doDelete"
return requests.request(
'POST', url, headers=kwargs.get('default_headers'))
@log
def trigger_pipeline_job(self, **kwargs):
"""Triggers a pipeline job for a repo. This will scan all branches for changes."""
bitbucket = kwargs.get('bitbucket')
jenkins = kwargs.get('jenkins')
url = f"http://{jenkins.get('host')}/job/{bitbucket.get('repo')}-build/build"
return requests.request(
'POST', url, headers=kwargs.get('default_headers'))
@log
def trigger_pipeline_branch_job(self, branch, **kwargs):
"""Triggers a pipeline job for a single branch in a repo."""
bitbucket = kwargs.get('bitbucket')
jenkins = kwargs.get('jenkins')
url = f"http://{jenkins.get('host')}/job/{bitbucket.get('repo')}-build"
url += f"/job/{urllib.parse.quote_plus(branch)}/build"
return requests.request(
'POST', url, headers=kwargs.get('default_headers'))