Files
tra-app/Jenkinsfile.ios
T
2026-03-30 03:16:23 +08:00

135 lines
5.6 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
pipeline {
agent {label 'macos'}
tools {
nodejs 'node22'
}
environment {
UNIAPP_APP_ID = '__UNI__EDE52' // uni-app 应用ID
APP_DIR = "Ios/HBuilder-Hello" // iOS 项目根目录
PROJECT_NAME = 'HBuilder-Hello' // 项目名称(xcodeproj 前缀)
ASSETS_DIR = "${APP_DIR}/${PROJECT_NAME}/Pandora/apps/${UNIAPP_APP_ID}/www" // 静态资源目录
SCHEME_NAME = 'HBuilder' // Xcode 编译 Scheme
CONFIGURATION = 'Release' // 编译模式:Release/Debug
ARCHIVE_PATH = "${APP_DIR}/build/HBuilder.xcarchive" // 归档文件输出路径
// ====================== 证书配置 ======================
CERT_DIR = 'certificate/ios' // 证书文件存放目录
P12_FILE = "${CERT_DIR}/开发证书.p12" // 开发证书 p12 路径
P12_PASSWORD = "Kup9dayLY#*" // p12 证书导入密码
PROFILE_FILE = "${CERT_DIR}/jiaixuedev.mobileprovision" // 描述文件路径
MAC_LOGIN_PWD = "667788" // Mac 登录密码(解锁钥匙串)
PROVISIONING_PROFILE_SPECIFIER = "jiaixuedev" // 描述文件名称
DEVELOPMENT_TEAM = "2EP6SRRN43" // 苹果开发者团队 ID
}
stages {
stage('打印环境变量') {
steps {
echo "使用的 UNIAPP_APP_ID${env.UNIAPP_APP_ID}"
echo "IOS资源目录:${env.ASSETS_DIR}"
sh "node -v" // 打印 NodeJS 版本
sh "npm -v" // 打印 NPM
}
}
stage('清理旧构建') {
steps {
sh "rm -rf dist/" // 清理 UniApp 打包生成的 dist 目录
}
}
// stage('安装依赖') {
// steps {
// echo "✅ 安装 UniApp 依赖(忽略平台+开权限+强制)"
// sh "npm install --force --unsafe-perm --ignore-platform"
// }
// }
stage('读取 manifest 版本号 → 写入环境变量') {
steps {
script {
// 2. 读取并设置为 环境变量(全局可用)
env.versionName = sh(
script: '''
node -p "require('json5').parse(require('fs').readFileSync('./src/manifest.json','utf8')).versionName"
''',
returnStdout: true
).trim()
env.versionCode = sh(
script: '''
node -p "require('json5').parse(require('fs').readFileSync('./src/manifest.json','utf8')).versionCode"
''',
returnStdout: true
).trim()
}
// 测试输出(你能看到成功了)
echo "✅ 版本名称:${env.versionName}"
echo "✅ 版本号:${env.versionCode}"
}
}
stage('安装证书 & 描述文件') {
steps {
sh '''
# =============== 安装 p12 证书 ===============
security unlock-keychain -p ${MAC_LOGIN_PWD} ~/Library/Keychains/login.keychain-db
security import ${P12_FILE} -k ~/Library/Keychains/login.keychain-db -P ${P12_PASSWORD} -A
'''
}
}
// stage('打包uniapp') {
// steps {
// sh "npm run build:app-plus:${env.BRANCH_NAME}"
// }
// }
// stage('复制UniApp资源到目录') {
// steps {
// echo "开始复制 dist 资源到 ${ASSETS_DIR}"
// // 先创建目标目录(防止目录不存在报错)
// sh "mkdir -p ${ASSETS_DIR}"
// // 把 dist 里所有文件 复制 到安卓资源目录(推荐)
// sh "cp -rf dist/build/app/* ${ASSETS_DIR}/"
// echo "✅ 资源复制完成"
// }
// }
// ====================== 构建 IPA ======================
// stage('========== 🗑️清理旧构建内容 ==========') {
// steps {
// sh """
// xcodebuild clean \\
// -project ${APP_DIR}/${PROJECT_NAME}.xcodeproj \\
// -scheme ${SCHEME_NAME} \\
// -configuration ${CONFIGURATION}
// """
//
// }
// }
// stage('开始归档项目') {
// steps {
// sh '''
// xcodebuild archive \\
// -project ${APP_DIR}/${PROJECT_NAME}.xcodeproj \\
// -scheme ${SCHEME_NAME} \\
// -configuration ${CONFIGURATION} \\
// -archivePath ${ARCHIVE_PATH} \\
// -destination generic/platform=iOS \\
// MARKETING_VERSION=${versionName} \\
// CURRENT_PROJECT_VERSION=${versionCode} \\
// CODE_SIGN_STYLE=Manual \\
// PROVISIONING_PROFILE_SPECIFIER=${PROVISIONING_PROFILE_SPECIFIER} \\
// DEVELOPMENT_TEAM=${DEVELOPMENT_TEAM}
// '''
// }
// }
}
post {
always {
echo '流水线已结束'
}
success {
echo '🎉 项目部署成功!'
}
failure {
echo '⚠️ 部署失败,请检查日志!'
}
}
}