Skip to content
Merged

Dev #19

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# permission 路由模式,动态路由,从接口获取, 动态渲染,不需要在 src/router/routes/modules 目录下配置路由
VITE_APP_ROUTER_MODE='permission'

VITE_TITLE='Slash Admin'
VITE_TITLE='React Admin'

VITE_PORT=3005

Expand Down
123 changes: 123 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
pipeline {
agent any
environment {
NPM_REGISTRY = 'https://registry.npmmirror.com' // 国内镜像加速
APP_NAME = 'react-admin' // 项目名称
}
tools {
nodejs 'node 20' // 确保与全局配置名称一致
}
stages {
// 阶段1:拉取代码
stage('Git Check') {
steps {
checkout scm // 从GitHub拉取代码
}
}
// 阶段2:安装依赖
stage('Install Dependencies') {
steps {
script {
sh 'node -v'
sh 'which npm' // 检查 npm 是否存在
sh "npm ci --registry=${NPM_REGISTRY}"
// sh 'npm ci'
}
}
}
// 阶段3:格式化 & 代码检查
stage('Format Code & Lint Code') {
steps {
sh 'npm run lint:format'
// sh 'npm run lint:fix'
}
}
// 阶段4:构建打包项目,并压缩文件
stage('Build Aplication') {
steps {
sh 'npm run build'
sh "rm -f ${APP_NAME}.zip" // 新增:清理旧文件
sh "zip -r ${APP_NAME}.zip . -x 'node_modules/*'"
// 归档产物(ZIP文件和原始目录)
archiveArtifacts artifacts: '*.zip', allowEmptyArchive: false
}
}
// 阶段5:运行单元测试
// stage('Jest Check') {
// steps {
// sh 'npm run test'
// // junit '**/test-results.xml' // 收集测试报告(需配置Jest或JUnit输出)[2](@ref)
// // junit 'test-results/junit.xml' // 收集测试报告
// // 归档产物(ZIP文件和原始目录)
// archiveArtifacts artifacts: 'coverage/lcov-report/index.html', allowEmptyArchive: false
// }
// }
// 阶段5:Nginx 部署
stage('Deploy TO Nginx') {
steps {
script {
def execCommand = """
# 启用详细日志和错误退出
set -ex
# 加载 nvm 环境变量(关键步骤)
source /root/.nvm/nvm.sh
# 进入项目目录
cd /var/www/${APP_NAME} || { echo '目录切换失败'; exit 1; }
# 解压构建产物
unzip -o ${APP_NAME}.zip || { echo '解压失败'; exit 1; }
# 删除 ZIP 文件
rm -f ${APP_NAME}.zip
chmod -R 755 .
# 检查 Nginx 配置 并重启
nginx -t && systemctl reload nginx
"""
// source /root/.nvm/nvm.sh
// npm config set prefix "/root/.nvm/versions/node/v20.10.0"

// 插件将构建产物部署到远程服务器
sshPublisher(
publishers: [
sshPublisherDesc(
configName: 'my ssh server',
transfers: [
sshTransfer(
// 指定要传输的文件
sourceFiles: '*.zip',
// 移除文件路径前缀
// removePrefix: 'dist',
// 远程服务器上的目标目录
remoteDirectory: "/${APP_NAME}",
// 执行的命令
execCommand: execCommand
)
],
verbose: true
)
]
)
}
}
}
}
post {
always {
script {
// 发送构建结果通知
emailext(
subject: '$DEFAULT_SUBJECT',
body: '$DEFAULT_CONTENT',
mimeType: 'text/html',
to: 'a15277019572@aliyun.com',
attachmentsPattern: '*.zip, coverage/lcov-report/index.html', // 指定附件路径
recipientProviders: [
[$class: 'CulpritsRecipientProvider'], // 通知代码提交者
[$class: 'RequesterRecipientProvider'] // 通知触发构建的用户
],
attachLog: true // 附加构建日志
)
}
// 清理工作空间(可选)
cleanWs()
}
}
}
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ services:
build:
context: .
ports:
- "3001:80"
- "3010:80"
restart: always
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<head>
<meta charset="UTF-8" />
<!-- <link rel="icon" type="image/svg+xml" href="/favicon.ico" /> -->
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title><%- title %></title>
</head>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"tailwindcss": "^3.3.3",
"ts-node": "^10.9.1",
"typescript": "^5.2.2",
"vite": "^5.4.9",
"vite": "^5.4.18",
"vite-plugin-checker": "^0.9.1",
"vite-plugin-compression": "^0.5.1",
"vite-plugin-html": "^3.2.2",
Expand Down
Loading