"""E2E 파이프라인 최종 검증: 실제 deploy trigger → 배포+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!' GITEA_B64 = base64.b64encode(b'zio:Zio@Admin2026!').decode() def run(label, cmd, timeout=30): print(f'\n[{label}]') _, o, _ = c.exec_command(cmd, timeout=timeout) out = o.read().decode('utf-8','replace').strip() if out: print(out[:600]) return out # 1. 현재 build 번호 기록 _, o, _ = c.exec_command(f'curl -sf -u "{A}" {J}/job/guardia-itsm/api/json 2>/dev/null', timeout=10) d = json.loads(o.read().decode('utf-8','replace')) build_before = d.get('lastBuild', {}).get('number', 0) print(f'빌드 전 lastBuild: #{build_before}') # 2. Gitea push 시뮬레이션 (webhook 직접 호출) run('push 시뮬레이션 → 배포+Jenkins', "curl -sf -X POST http://localhost:9999 " "-H 'Content-Type: application/json' " "-H 'X-Gitea-Event: push' " "-d '{\"repository\":{\"name\":\"guardia-itsm\"},\"ref\":\"refs/heads/main\"}' 2>/dev/null") # 3. 배포 완료 대기 print('\n배포 + Jenkins 빌드 대기...') for i in range(15): time.sleep(4) _, 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) building = d.get('lastBuild', {}).get('building', False) if lb > build_before else None if lb > build_before: if building == False: _, 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')) print(f' ✅ 새 빌드 #{lb}: {bd.get("result")}') break else: print(f' build #{lb} 진행중...') else: _, o3, _ = c.exec_command('tail -3 /var/log/zioinfo/deploy.log 2>/dev/null', timeout=5) status = o3.read().decode('utf-8','replace').strip().splitlines()[-1] if o3.read else '...' except Exception as e: print(f' 오류: {e}') # 4. 최종 결과 run('배포 로그 마지막', 'tail -8 /var/log/zioinfo/deploy.log 2>/dev/null') run('Jenkins 빌드 콘솔 (마지막 20줄)', f'curl -sf -u "{A}" {J}/job/guardia-itsm/lastBuild/consoleText 2>/dev/null | tail -20') run('guardia 서비스 상태', 'systemctl is-active guardia') c.close()