forked from pycontribs/jira
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmake_local_jira_user.py
53 lines (46 loc) · 1.56 KB
/
make_local_jira_user.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
"""Attempts to create a test user,
as the empty JIRA instance isn't provisioned with one.
"""
import time
from os import environ
import requests
from jira import JIRA
CI_JIRA_URL = environ["CI_JIRA_URL"]
def add_user_to_jira():
try:
JIRA(
CI_JIRA_URL,
basic_auth=(environ["CI_JIRA_ADMIN"], environ["CI_JIRA_ADMIN_PASSWORD"]),
).add_user(
username=environ["CI_JIRA_USER"],
email="[email protected]",
fullname=environ["CI_JIRA_USER_FULL_NAME"],
password=environ["CI_JIRA_USER_PASSWORD"],
)
print("user {}".format(environ["CI_JIRA_USER"]))
except Exception as e:
if "username already exists" not in str(e):
raise e
if __name__ == "__main__":
start_time = time.time()
timeout_mins = 15
print(
"waiting for instance of jira to be running, to add a user for CI system:\n timeout = {} mins".format(
timeout_mins
)
)
while True:
try:
requests.get(CI_JIRA_URL + "rest/api/2/permissions")
print("JIRA IS REACHABLE")
add_user_to_jira()
break
except (requests.exceptions.Timeout, requests.exceptions.ConnectionError) as ex:
print(
"encountered {} while waiting for the JiraServer docker".format(str(ex))
)
time.sleep(20)
if start_time + 60 * timeout_mins < time.time():
raise TimeoutError(
"Jira server wasn't reachable within timeout {}".format(timeout_mins)
)