70 lines
2.8 KiB
Python
70 lines
2.8 KiB
Python
"""Jenkins 빌드 완료 대기 + 전체 파이프라인 최종 검증"""
|
|
import paramiko, sys, json, time, base64
|
|
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])
|
|
|
|
# 빌드 완료 대기
|
|
print('Jenkins 빌드 #4 대기...')
|
|
for i in range(15):
|
|
time.sleep(5)
|
|
_, o, _ = c.exec_command(
|
|
f'curl -sf -u "{A}" {J}/job/guardia-itsm/api/json 2>/dev/null', timeout=10)
|
|
try:
|
|
d = json.loads(o.read().decode('utf-8','replace'))
|
|
lb = d.get('lastBuild', {}).get('number', 0)
|
|
nb = d.get('nextBuildNumber', 0)
|
|
print(f' lastBuild=#{lb} nextBuild=#{nb}', end='')
|
|
if lb >= 4:
|
|
_, o2, _ = c.exec_command(
|
|
f'curl -sf -u "{A}" {J}/job/guardia-itsm/lastBuild/api/json 2>/dev/null', timeout=10)
|
|
bd = json.loads(o2.read().decode('utf-8','replace'))
|
|
result = bd.get('result')
|
|
building = bd.get('building')
|
|
print(f' → {result} building={building}')
|
|
if not building:
|
|
print(f'\n✅ build #{lb}: {result}')
|
|
break
|
|
else:
|
|
print()
|
|
except:
|
|
print()
|
|
|
|
# 최종 결과
|
|
run('build #4 콘솔 로그',
|
|
f'curl -sf -u "{A}" {J}/job/guardia-itsm/lastBuild/consoleText 2>/dev/null | tail -15')
|
|
|
|
# 전체 E2E 파이프라인 최종 상태
|
|
print('\n' + '='*55)
|
|
print('GUARDiA CI/CD 파이프라인 최종 현황')
|
|
print('='*55)
|
|
print('\n📋 구성 요소:')
|
|
print(' - Gitea repos (5개): webhook 2개씩 (port 9999 + Jenkins)')
|
|
print(' - deploy_server.py (port 9999): 즉시 배포 + Jenkins 트리거')
|
|
print(' - Jenkins (port 9080): Build + Test + ITSM 메신저 알림')
|
|
|
|
run('webhook 서버', 'systemctl is-active zioinfo-deploy && echo "port 9999 ✅"')
|
|
run('5개 job 상태',
|
|
f'curl -sf -u "{A}" {J}/api/json 2>/dev/null | '
|
|
"python3 -c \"import sys,json; d=json.load(sys.stdin); "
|
|
"[print(' ',j['name'].ljust(22), j['color'], '✅' if j['color']=='blue' else '⚠️') for j in d['jobs']]\" 2>/dev/null")
|
|
run('guardia + zioinfo 서비스',
|
|
'echo guardia: $(systemctl is-active guardia); echo zioinfo: $(systemctl is-active zioinfo)')
|
|
|
|
print('\n📌 자동 배포 흐름:')
|
|
print(' 1. 로컬 수정 → repos/에 commit')
|
|
print(' 2. sync_workspace_to_repos.py 실행 → Gitea push')
|
|
print(' 3. Gitea webhook → port 9999 → 즉시 배포 ✅')
|
|
print(' 4. deploy_server.py → Jenkins 트리거 ✅')
|
|
print(' 5. Jenkins: Build + Test → ITSM 메신저 알림 ✅')
|
|
|
|
c.close()
|