zioinfo-mail/scripts/setup/jenkins_setup2.py
DESKTOP-TKLFCPR\ython 28d3ba4836 refactor(cleanup): commit folder reorganization - scripts/, _archive/, docs/ restructure
- Move backend/frontend/messenger/ old paths to _archive/
- Reorganize scripts into scripts/deploy, check, push, setup, misc
- Move docs (pptx, docx) to docs/
- Add .claude agents and skills for fullstack/folder-cleanup harness
- workspace/ projects remain intact

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-01 19:43:09 +09:00

64 lines
2.5 KiB
Python

import paramiko, sys, time
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect('101.79.17.164', username='root', password='1q2w3e!Q', timeout=30)
JENKINS = 'http://127.0.0.1:9080'
ADMIN_PW = 'admin'
def run(label, cmd, timeout=60):
print(f'\n[{label}]')
_, o, e = client.exec_command(cmd, timeout=timeout)
out = o.read().decode('utf-8', errors='replace').strip()
err = e.read().decode('utf-8', errors='replace').strip()
if out: print(out[:400])
if err:
bad = [l for l in err.splitlines() if not any(k in l.lower() for k in ['warn','info'])]
if bad: print('ERR:', '\n'.join(bad[:2]))
return out
# 내부 포트로 확인
run('내부 API 확인', f"""
HTTP=$(curl -sf -o /dev/null -w "%{{http_code}}" {JENKINS}/api/json -u admin:{ADMIN_PW} 2>/dev/null)
echo "HTTP: $HTTP"
curl -sf {JENKINS}/api/json -u admin:{ADMIN_PW} 2>/dev/null | python3 -c "
import sys,json; d=json.load(sys.stdin); print('Jenkins', d.get('fullName',d.get('mode','OK')))
" 2>/dev/null || echo "auth 실패 - 비밀번호 시도 필요"
""")
# 초기 비밀번호로 시도
run('초기 비밀번호로 확인', f"""
INIT=$(cat /var/lib/jenkins/secrets/initialAdminPassword 2>/dev/null)
HTTP=$(curl -sf -o /dev/null -w "%{{http_code}}" {JENKINS}/api/json -u admin:$INIT 2>/dev/null)
echo "초기비번 HTTP: $HTTP"
""")
# 플러그인 설치 (내부 포트)
run('필수 플러그인 설치', f"""
java -jar /tmp/jenkins-cli.jar -s {JENKINS} -auth admin:{ADMIN_PW} install-plugin \
git workflow-aggregator pipeline-stage-view credentials-binding \
ssh-agent nodejs timestamper ansicolor http_request junit \
2>/dev/null && echo "플러그인 설치 완료"
# 실패 시 초기 비밀번호로 재시도
if [ $? -ne 0 ]; then
INIT=$(cat /var/lib/jenkins/secrets/initialAdminPassword)
java -jar /tmp/jenkins-cli.jar -s {JENKINS} -auth admin:$INIT install-plugin \
git workflow-aggregator pipeline-stage-view credentials-binding \
ssh-agent nodejs timestamper ansicolor http_request junit \
&& echo "초기비번으로 플러그인 설치 완료"
fi
""", timeout=120)
run('Jenkins 재시작', f"""
java -jar /tmp/jenkins-cli.jar -s {JENKINS} -auth admin:{ADMIN_PW} restart 2>/dev/null || \
java -jar /tmp/jenkins-cli.jar -s {JENKINS} -auth admin:$(cat /var/lib/jenkins/secrets/initialAdminPassword) restart 2>/dev/null || \
systemctl restart jenkins
sleep 10
systemctl is-active jenkins
""")
client.close()