f34104b721
Capacitor 확장으로 git push 시 Mobile Jenkins 빌드, PC 탭 Android/iPad 다운로드, 앱 내 APK 업데이트, iOS TestFlight API 및 Capacitor ios 프로젝트를 추가한다. Co-authored-by: Cursor <cursoragent@cursor.com>
81 lines
2.6 KiB
Bash
Executable File
81 lines
2.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Git push(main) 후 Jenkins goldenChart-Mobile-Pipeline 트리거
|
|
set -euo pipefail
|
|
|
|
JENKINS_URL="${JENKINS_URL:-${GC_MOBILE_JENKINS_URL:-http://127.0.0.1:8090}}"
|
|
JENKINS_JOB="${JENKINS_JOB:-${GC_MOBILE_JENKINS_JOB:-goldenChart-Mobile-Pipeline}}"
|
|
JENKINS_USER="${JENKINS_USER:-${GC_MOBILE_JENKINS_USER:-}}"
|
|
JENKINS_TOKEN="${JENKINS_TOKEN:-${GC_MOBILE_JENKINS_TOKEN:-}}"
|
|
JENKINS_TRIGGER_TOKEN="${JENKINS_TRIGGER_TOKEN:-${GC_MOBILE_JENKINS_TRIGGER_TOKEN:-goldenchart-mobile-build}}"
|
|
LOG_TAG="[trigger-mobile]"
|
|
|
|
log() { echo "$(date '+%Y-%m-%d %H:%M:%S') $LOG_TAG $*"; }
|
|
|
|
JENKINS_URL="${JENKINS_URL%/}"
|
|
JOB_API="${JENKINS_URL}/job/${JENKINS_JOB// /%20}"
|
|
|
|
curl_get() {
|
|
if [[ -n "$JENKINS_USER" && -n "$JENKINS_TOKEN" ]]; then
|
|
curl -sf -u "${JENKINS_USER}:${JENKINS_TOKEN}" "$@"
|
|
else
|
|
curl -sf "$@"
|
|
fi
|
|
}
|
|
|
|
curl_post() {
|
|
if [[ -n "$JENKINS_USER" && -n "$JENKINS_TOKEN" ]]; then
|
|
curl -sf -X POST -u "${JENKINS_USER}:${JENKINS_TOKEN}" "$@"
|
|
else
|
|
curl -sf -X POST "$@"
|
|
fi
|
|
}
|
|
|
|
log "Jenkins mobile build — $JENKINS_JOB @ $JENKINS_URL"
|
|
|
|
if ! curl -sf -o /dev/null "${JENKINS_URL}/login" 2>/dev/null; then
|
|
log "[ERROR] Jenkins unreachable: $JENKINS_URL"
|
|
exit 1
|
|
fi
|
|
|
|
if curl_get "${JOB_API}/lastBuild/api/json?tree=building" 2>/dev/null | grep -q '"building":true'; then
|
|
log "[SKIP] 이미 빌드 진행 중"
|
|
exit 0
|
|
fi
|
|
|
|
CRUMB_HDR=()
|
|
CRUMB_JSON="$(curl_get "${JENKINS_URL}/crumbIssuer/api/json" 2>/dev/null || true)"
|
|
if [[ -n "$CRUMB_JSON" ]]; then
|
|
FIELD="$(node -e "try{console.log(JSON.parse(process.argv[1]).crumbRequestField||'')}catch{}" "$CRUMB_JSON" 2>/dev/null || true)"
|
|
VAL="$(node -e "try{console.log(JSON.parse(process.argv[1]).crumb||'')}catch{}" "$CRUMB_JSON" 2>/dev/null || true)"
|
|
if [[ -n "$FIELD" && -n "$VAL" ]]; then
|
|
CRUMB_HDR=(-H "${FIELD}: ${VAL}")
|
|
fi
|
|
fi
|
|
|
|
if ((${#CRUMB_HDR[@]})); then
|
|
if curl_post "${CRUMB_HDR[@]}" -H "Content-Type: application/x-www-form-urlencoded" \
|
|
"${JOB_API}/build?token=${JENKINS_TRIGGER_TOKEN}"; then
|
|
log "빌드 큐 등록 완료 (token)"
|
|
exit 0
|
|
fi
|
|
|
|
if curl_post "${CRUMB_HDR[@]}" -H "Content-Type: application/x-www-form-urlencoded" "${JOB_API}/build"; then
|
|
log "빌드 큐 등록 완료"
|
|
exit 0
|
|
fi
|
|
else
|
|
if curl_post -H "Content-Type: application/x-www-form-urlencoded" \
|
|
"${JOB_API}/build?token=${JENKINS_TRIGGER_TOKEN}"; then
|
|
log "빌드 큐 등록 완료 (token)"
|
|
exit 0
|
|
fi
|
|
|
|
if curl_post -H "Content-Type: application/x-www-form-urlencoded" "${JOB_API}/build"; then
|
|
log "빌드 큐 등록 완료"
|
|
exit 0
|
|
fi
|
|
fi
|
|
|
|
log "[ERROR] Jenkins build trigger failed"
|
|
exit 1
|