51 lines
2.1 KiB
Python
51 lines
2.1 KiB
Python
"""Jenkins zioinfo-mail 빌드 트리거 + 결과 대기"""
|
|
import paramiko, sys, json, time
|
|
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
|
|
c = paramiko.SSHClient(); c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect('101.79.17.164', username='root', password='1q2w3e!Q', timeout=15)
|
|
J = 'http://127.0.0.1:9080'; A = 'admin:Admin@2026!'
|
|
|
|
def run(label, cmd, timeout=20):
|
|
print(f'\n[{label}]')
|
|
_, o, _ = c.exec_command(cmd, timeout=timeout)
|
|
print(o.read().decode('utf-8','replace').strip()[:600])
|
|
|
|
# crumb
|
|
_, o, _ = c.exec_command(f'curl -sf -u "{A}" {J}/crumbIssuer/api/json 2>/dev/null', timeout=10)
|
|
try:
|
|
cd = json.loads(o.read().decode('utf-8','replace').strip())
|
|
CH = f'{cd["crumbRequestField"]}: {cd["crumb"]}'
|
|
except: CH = 'Jenkins-Crumb: x'
|
|
|
|
# Gitea repo 파일 목록 확인
|
|
run('Gitea zioinfo-mail 파일 목록',
|
|
f'curl -sf "http://127.0.0.1:9003/api/v1/repos/zio/zioinfo-mail/contents/" '
|
|
f'-H "Authorization: Basic emhvOlppb0BBZG1pbjIwMjYh" 2>/dev/null | '
|
|
'python3 -c "import sys,json; [print(f[\'name\'],f[\'type\']) for f in json.load(sys.stdin)[:10]]" 2>/dev/null')
|
|
|
|
# Jenkins 재빌드
|
|
run('Jenkins 재빌드 트리거',
|
|
f'curl -sf -X POST -u "{A}" -H "{CH}" {J}/job/zioinfo-mail/build 2>/dev/null && echo "트리거됨"')
|
|
|
|
print('\n빌드 대기 (120초)...')
|
|
for i in range(24):
|
|
time.sleep(5)
|
|
_, o2, _ = c.exec_command(
|
|
f'curl -sf -u "{A}" {J}/job/zioinfo-mail/lastBuild/api/json 2>/dev/null', timeout=10)
|
|
try:
|
|
d = json.loads(o2.read().decode('utf-8','replace'))
|
|
num = d.get('number','?'); result = d.get('result','진행중'); building = d.get('building',True)
|
|
print(f' #{num}: {result} building={building}')
|
|
if not building: break
|
|
except: pass
|
|
|
|
run('콘솔 로그',
|
|
f'curl -sf -u "{A}" {J}/job/zioinfo-mail/lastBuild/consoleText 2>/dev/null | tail -20')
|
|
|
|
# 전체 job 상태
|
|
run('전체 job 상태',
|
|
f'curl -sf -u "{A}" {J}/api/json 2>/dev/null | '
|
|
'python3 -c "import sys,json; [print(j[\'name\'].ljust(22),j[\'color\']) for j in json.load(sys.stdin)[\'jobs\']]" 2>/dev/null')
|
|
|
|
c.close()
|