Files
tra-app/Jenkinsfile.ios
T
2026-03-29 16:02:19 +08:00

103 lines
3.7 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__EDE0E52'
APP_DIR = "Ios/HBuilder-Hello/HBuilder-Hello"
ASSETS_DIR = "${APP_DIR}/Pandora/apps/${UNIAPP_APP_ID}/www"
PROJECT_NAME = 'HBuilder-Hello'
SCHEME_NAME = 'HBuilder'
CONFIGURATION = 'Release'
}
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 目录
// sh "rm -rf android/simpleDemo/build/" // 清理 Android 项目构建缓存
sh "rm -rf ${ASSETS_DIR}" // 清理旧的 APP 资源文件目录
}
}
stage('安装依赖') {
steps {
// echo "✅ 从清华源安装缺失的 uts 二进制包"
// sh "npm install @dcloudio/uts-linux-x64-gnu --force --registry=https://registry.npmmirror.com"
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('打包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('配置SDK & 赋予权限 & 编译IOS') {
steps {
echo "========== 🗑️清理旧构建内容 =========="
sh """
xcodebuild clean -workspace ${PROJECT_NAME}.xcworkspace \\
-scheme ${SCHEME_NAME} \\
-configuration ${configuration} \\
clean
"""
}
}
}
post {
always {
echo '流水线已结束'
}
success {
echo '🎉 项目部署成功!'
}
failure {
echo '⚠️ 部署失败,请检查日志!'
}
}
}