55 lines
1.9 KiB
Python
55 lines
1.9 KiB
Python
"""Jenkins job 빌드 트리거 + 결과 확인"""
|
|
import paramiko, sys, time, json
|
|
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)
|
|
out = o.read().decode('utf-8','replace').strip()
|
|
if out: print(out[:600])
|
|
return out
|
|
|
|
# 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())
|
|
CRUMB = f'-H "{cd["crumbRequestField"]}: {cd["crumb"]}"'
|
|
except:
|
|
CRUMB = ''
|
|
|
|
# guardia-itsm 빌드 트리거
|
|
run('guardia-itsm 빌드 트리거',
|
|
f'curl -sf -X POST -u "{A}" {CRUMB} {J}/job/guardia-itsm/build 2>/dev/null && echo "트리거됨"')
|
|
|
|
time.sleep(5)
|
|
|
|
# 빌드 번호 확인
|
|
run('guardia-itsm 빌드 번호',
|
|
f'curl -sf -u "{A}" {J}/job/guardia-itsm/api/json 2>/dev/null | '
|
|
'python3 -c "import sys,json; d=json.load(sys.stdin); '
|
|
'print(\'nextBuildNumber:\', d.get(\'nextBuildNumber\'), \'lastBuild:\', d.get(\'lastBuild\',{}).get(\'number\',\'없음\'))" 2>/dev/null')
|
|
|
|
time.sleep(8)
|
|
|
|
# 빌드 로그 확인
|
|
run('guardia-itsm 빌드 콘솔 로그',
|
|
f'curl -sf -u "{A}" {J}/job/guardia-itsm/lastBuild/consoleText 2>/dev/null | head -40')
|
|
|
|
# zioinfo-web 빌드 트리거
|
|
run('zioinfo-web 빌드 트리거',
|
|
f'curl -sf -X POST -u "{A}" {CRUMB} {J}/job/zioinfo-web/build 2>/dev/null && echo "트리거됨"')
|
|
|
|
time.sleep(3)
|
|
|
|
# 전체 job 상태
|
|
run('전체 job 상태',
|
|
f'curl -sf -u "{A}" {J}/api/json 2>/dev/null | '
|
|
'python3 -c "import sys,json; [print(j[\'name\'], j[\'color\']) for j in json.load(sys.stdin)[\'jobs\']]" 2>/dev/null')
|
|
|
|
c.close()
|