Files
tra-app/Jenkinsfile
T
2026-03-29 00:07:19 +08:00

68 lines
2.5 KiB
Groovy
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 any
tools {
nodejs 'node22'
}
environment {
UNIAPP_APP_ID = '__UNI__EDE0E52'
ANDROID_ASSETS_DIR = "Android/simpleDemo/src/main/assets/apps/${UNIAPP_APP_ID}/www"
// Android 构建环境
ANDROID_HOME = '/usr/local/android-sdk' // 你的 Jenkins 服务器 SDK 路径
GRADLE_OPTS = '-Dorg.gradle.daemon=false -Dorg.gradle.parallel=true'
}
stages {
stage('打印环境变量') {
steps {
echo "使用的 UNIAPP_APP_ID${env.UNIAPP_APP_ID}"
echo "安卓资源目录:${env.ANDROID_ASSETS_DIR}"
sh "node -v" // 打印 NodeJS 版本
sh "npm -v" // 打印 NPM
sh "java -version"
sh "./Android/simpleDemo/gradlew -v" // 验证 gradle 可用
}
}
stage('清理旧构建') {
steps {
sh "rm -rf dist/" // 清理 UniApp 打包生成的 dist 目录
sh "rm -rf android/simpleDemo/build/" // 清理 Android 项目构建缓存
sh "rm -rf ${ANDROID_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('打包uniapp') {
steps {
sh "npm run build:app-plus:${env.BRANCH_NAME}"
}
}
stage('复制UniApp资源到安卓assets目录') {
steps {
echo "开始复制 dist 资源到 ${ANDROID_ASSETS_DIR}"
// 先创建目标目录(防止目录不存在报错)
sh "mkdir -p ${ANDROID_ASSETS_DIR}"
// 把 dist 里所有文件 复制 到安卓资源目录(推荐)
sh "cp -rf dist/build/app/* ${ANDROID_ASSETS_DIR}/"
echo "✅ 资源复制完成"
}
}
}
post {
always {
echo '流水线已结束'
}
success {
echo '🎉 项目部署成功!'
}
failure {
echo '⚠️ 部署失败,请检查日志!'
}
}
}