43 lines
1.6 KiB
Python
43 lines
1.6 KiB
Python
"""Jenkins zioinfo-mail workspace 정리 후 재빌드"""
|
|
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=30):
|
|
print(f'\n[{label}]')
|
|
_, o, _ = c.exec_command(cmd, timeout=timeout)
|
|
print(o.read().decode('utf-8','replace').strip()[:400])
|
|
|
|
# workspace 초기화
|
|
run('workspace 초기화',
|
|
'rm -rf /var/lib/jenkins/workspace/zioinfo-mail && echo "초기화 완료"')
|
|
|
|
# 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'
|
|
|
|
run('재빌드 트리거',
|
|
f'curl -sf -X POST -u "{A}" -H "{CH}" {J}/job/zioinfo-mail/build 2>/dev/null && echo "트리거됨"')
|
|
|
|
print('\n빌드 대기 (180초, npm install 포함)...')
|
|
for i in range(36):
|
|
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 -25')
|
|
|
|
c.close()
|