Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ci
Path: blob/main/scripts/jenkins/call.py
1130 views
1
#!/usr/local/bin/python3
2
3
import base64
4
import configparser
5
import urllib.parse
6
import urllib.request
7
8
config = configparser.ConfigParser()
9
config.read('config.ini')
10
11
file = open('script.groovy', 'r', encoding='UTF-8')
12
groovy_script = file.read()
13
file.close()
14
15
url = "{}/scriptText".format(config['general']['host'])
16
parameters = {'script':groovy_script}
17
data = urllib.parse.urlencode(parameters).encode('utf-8')
18
req = urllib.request.Request(url=url, data=data)
19
20
username = config['cred']['username']
21
password = config['cred']['password']
22
cred = base64.b64encode('{}:{}'.format(username,password).encode('utf-8'))
23
req.add_header("Authorization", "Basic {}".format(cred.decode('utf-8')))
24
25
s = urllib.request.urlopen(req)
26
result = s.read().decode('utf-8')
27
print(result)
28
29