forked from bjgill/duris
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jenkins.py
executable file
·66 lines (45 loc) · 1.7 KB
/
jenkins.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import requests
import argparse
from config import config
parser = argparse.ArgumentParser()
parser.add_argument("branch")
parser.add_argument("email", default=None)
parser.add_argument("username")
parser.add_argument("password")
args = parser.parse_args()
def get_master_config():
"""
Gets the config.xml file for the Jenkins build job for origin/master.
"""
job_get_url = "{}/job/{}/config.xml".format(config['jenkins_url'],
config['master_job'])
auth = (args.username, args.password)
headers = {'Content-Type': 'application/xml'}
response = requests.get(job_get_url, auth=auth, headers=headers)
return response.text
def main():
master_config = get_master_config()
branch_config = master_config.replace("origin/master", args.branch)
if args.email is not None:
branch_config = branch_config.replace(
"<recipients></recipients>",
"<recipients>{}</recipients>".format(args.email))
print(branch_config)
job_create_url = config['jenkins_url'] + "/createItem"
auth = (args.username, args.password)
params = {'name': args.branch}
headers = {'Content-Type': 'application/xml'}
response = requests.post(job_create_url,
auth=auth,
headers=headers,
params=params,
data=branch_config)
print(response.status_code)
print(response.text)
if __name__ == "__main__":
main()