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()[:400]) run('현재 권한', 'ls -la /opt/mail/') run('권한 수정', 'chown -R jenkins:jenkins /opt/mail/ && chmod -R 775 /opt/mail/ && echo ok') run('수정 후 권한', 'ls -la /opt/mail/') _, 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빌드 대기...') 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 -15') 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()