forked from tlc-pack/ci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_trust_on_jobs.py
51 lines (37 loc) · 1.46 KB
/
set_trust_on_jobs.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
import argparse
import os
import jenkins
USER = os.environ["JENKINS_USER"]
PW = os.environ["JENKINS_PW"]
def add_fork_trust_plugin(xml: str) -> str:
nobody = '<trust class="org.jenkinsci.plugins.github_branch_source.ForkPullRequestDiscoveryTrait$TrustNobody"/>'
some_people = (
'<trust class="org.jenkinsci.plugins.githubScmTraitNotificationContext.'
'ForkPullRequestDiscoveryTrait$TrustSomePeople" plugin="[email protected]"/>'
)
return xml.replace(nobody, some_people)
def test():
with open("out.xml") as f:
content = f.read()
content = add_fork_trust_plugin(content)
with open("out.xml", "w") as f:
f.write(content)
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Set the job config XML for octoml- and tvm- jobs in Jenkins"
)
parser.parse_args()
server = jenkins.Jenkins("https://ci.tlcpack.ai", username=USER, password=PW) # type: ignore[attr-defined]
jobs = server.get_jobs()
to_update = []
for job in jobs:
name = job["fullname"]
if name.startswith("tvm-") or name.startswith("octoml-"):
to_update.append(name)
for name in to_update:
print(f"Updating fork trust plugin for {name}", end="")
config = server.get_job_config(name)
new_config = add_fork_trust_plugin(config)
if config != new_config:
r = server.reconfig_job(name, new_config)
print(" done")