"""deploy_server.py Jenkins 인증 변수 수정""" import paramiko, sys, 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) 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()[:500]) run('Jenkins 인증 변수 확인', "grep -n 'JENKINS_USER\\|JENKINS_TOKEN\\|JENKINS_URL\\|jenkins_pass\\|admin' " "/opt/zioinfo/deploy_server.py | head -10") run('수정: Jenkins 인증 변수 업데이트', r"""python3 -c " with open('/opt/zioinfo/deploy_server.py', 'r') as f: content = f.read() # JENKINS_USER, JENKINS_TOKEN 수정 import re content = re.sub(r'JENKINS_USER\s*=\s*[\"\']\w+[\"\']\s*', 'JENKINS_USER = \"admin\"\n', content) content = re.sub(r'JENKINS_TOKEN\s*=\s*[\"\'][^\"\']+[\"\']\s*', 'JENKINS_TOKEN = \"Admin@2026!\"\n', content) with open('/opt/zioinfo/deploy_server.py', 'w') as f: f.write(content) print('수정 완료') " """) run('수정 후 확인', "grep -n 'JENKINS_USER\\|JENKINS_TOKEN\\|JENKINS_URL' /opt/zioinfo/deploy_server.py | head -5") run('서비스 재시작', 'systemctl restart zioinfo-deploy && sleep 2 && systemctl is-active zioinfo-deploy') # 직접 Jenkins API 호출 테스트 run('Jenkins API 직접 테스트', 'curl -sf -o /dev/null -w "%{http_code}" -X POST ' '"http://127.0.0.1:9080/job/guardia-itsm/build?token=gitea-build-2026" ' '-u "admin:Admin@2026!" ' '-H "$(curl -sf -u admin:Admin@2026! http://127.0.0.1:9080/crumbIssuer/api/json 2>/dev/null | ' 'python3 -c \'import sys,json; d=json.load(sys.stdin); print(d[chr(99)+chr(114)+chr(117)+chr(109)+chr(98)+chr(82)+chr(101)+chr(113)+chr(117)+chr(101)+chr(115)+chr(116)+chr(70)+chr(105)+chr(101)+chr(108)+chr(100)]+\": \"+d[chr(99)+chr(114)+chr(117)+chr(109)+chr(98)])\' 2>/dev/null)" 2>/dev/null') time.sleep(5) run('Jenkins 빌드 확인', 'curl -sf -u "admin:Admin@2026!" http://127.0.0.1:9080/job/guardia-itsm/api/json 2>/dev/null | ' 'python3 -c "import sys,json; d=json.load(sys.stdin); print(\'build #\'+str(d[\'lastBuild\'][\'number\']), \'next:\', d[\'nextBuildNumber\'])" 2>/dev/null') c.close()