优化Jenkinsfile
This commit is contained in:
Vendored
+1
-7
@@ -4,13 +4,7 @@ pipeline {
|
|||||||
nodejs 'NodeJS20'
|
nodejs 'NodeJS20'
|
||||||
}
|
}
|
||||||
stages {
|
stages {
|
||||||
stage('代码拉取') {
|
|
||||||
steps {
|
|
||||||
git url: 'http://118.25.129.153:3000/zhihui/suanfa.git',
|
|
||||||
branch: 'main'
|
|
||||||
echo '✅ 代码拉取成功'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage('设置NPM镜像'){
|
stage('设置NPM镜像'){
|
||||||
steps{
|
steps{
|
||||||
sh '''
|
sh '''
|
||||||
|
|||||||
@@ -7,23 +7,24 @@ http://jkadmin:11ed3ee565236054f1c9fd2623e75d80dc@118.25.129.153:3001/job/build-
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
流水线,可以加到SCM里。
|
流水线,可以加到SCM里。拉取部分就不需要了。
|
||||||
|
|
||||||
pipeline {
|
pipeline {
|
||||||
agent any
|
agent any
|
||||||
tools{
|
tools {
|
||||||
nodejs 'NodeJS20'
|
nodejs 'NodeJS20'
|
||||||
}
|
}
|
||||||
stages {
|
stages {
|
||||||
stage('代码拉取') {
|
// ❌ 删除 "代码拉取" 这个 stage,因为 Jenkins 已经自动拉取了
|
||||||
|
<!-- stage('代码拉取') {
|
||||||
steps {
|
steps {
|
||||||
git url: 'http://118.25.129.153:3000/zhihui/suanfa.git',
|
git url: 'http://118.25.129.153:3000/zhihui/suanfa.git',
|
||||||
branch: 'main'
|
branch: 'main'
|
||||||
echo '✅ 代码拉取成功'
|
echo '✅ 代码拉取成功'
|
||||||
}
|
}
|
||||||
}
|
} -->
|
||||||
stage('设置NPM镜像'){
|
stage('设置NPM镜像') {
|
||||||
steps{
|
steps {
|
||||||
sh '''
|
sh '''
|
||||||
npm config set registry https://mirrors.cloud.tencent.com/npm/
|
npm config set registry https://mirrors.cloud.tencent.com/npm/
|
||||||
echo "当前 npm 镜像源:"
|
echo "当前 npm 镜像源:"
|
||||||
@@ -31,18 +32,18 @@ pipeline {
|
|||||||
'''
|
'''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('安装依赖'){
|
stage('安装依赖') {
|
||||||
steps{
|
steps {
|
||||||
sh 'npm install'
|
sh 'npm install'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('执行依赖'){
|
stage('执行构建') {
|
||||||
steps{
|
steps {
|
||||||
sh 'npm run build'
|
sh 'npm run build'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('保存成果'){
|
stage('保存成果') {
|
||||||
steps{
|
steps {
|
||||||
archiveArtifacts artifacts: 'dist/**/*', allowEmptyArchive: true
|
archiveArtifacts artifacts: 'dist/**/*', allowEmptyArchive: true
|
||||||
echo '📦 构建产物已保存'
|
echo '📦 构建产物已保存'
|
||||||
}
|
}
|
||||||
@@ -51,28 +52,21 @@ pipeline {
|
|||||||
steps {
|
steps {
|
||||||
echo '🚀 开始部署前端文件...'
|
echo '🚀 开始部署前端文件...'
|
||||||
script {
|
script {
|
||||||
// 确保目标目录存在
|
|
||||||
sh 'mkdir -p /app/www'
|
sh 'mkdir -p /app/www'
|
||||||
// 清空旧文件
|
|
||||||
sh 'rm -rf /app/www/*'
|
sh 'rm -rf /app/www/*'
|
||||||
// 复制新构建的 dist 文件到挂载目录
|
|
||||||
sh 'cp -r dist/* /app/www/'
|
sh 'cp -r dist/* /app/www/'
|
||||||
|
|
||||||
echo '✅ 前端文件部署完成!'
|
echo '✅ 前端文件部署完成!'
|
||||||
|
|
||||||
// 可选:列出部署的文件以便验证
|
|
||||||
sh 'ls -la /app/www/ | head -10'
|
sh 'ls -la /app/www/ | head -10'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
post{
|
post {
|
||||||
success{
|
success {
|
||||||
echo '🎉 构建成功!'
|
echo '🎉 构建成功!'
|
||||||
}
|
}
|
||||||
failure{
|
failure {
|
||||||
echo '❌ 构建失败,请检查代码!'
|
echo '❌ 构建失败,请检查代码!'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user