1 changed files with 103 additions and 0 deletions
@ -0,0 +1,103 @@ |
|||||
|
//file:noinspection ALL |
||||
|
pipeline { |
||||
|
agent any |
||||
|
|
||||
|
environment { |
||||
|
projectName = 'lcc-work-server' |
||||
|
// 源码配置 |
||||
|
git = 'http://git.yvanui.com/luoyifan/LCC-WORLD-MODEL7.git' |
||||
|
gitCredentials = 'git_yvanui_com_lizhiwei' |
||||
|
// 构建配置 |
||||
|
baseDir = "${WORKSPACE}" |
||||
|
profiles = 'production' |
||||
|
port = "7722" |
||||
|
// 自定义环境变量 |
||||
|
JAVA_HOME = '/opt/jenkins-agent/env/java/jdk-17.0.11' |
||||
|
GRADLE_HOME = '/opt/jenkins-agent/env/gradle/gradle-6.8.3' |
||||
|
MAVEN_HOME = '/opt/jenkins-agent/env/maven/apache-maven-3.9.6' |
||||
|
NODE_HOME = '/opt/node/node-v18.19.0-linux-x64-glibc-217' |
||||
|
PNPM_HOME="/usr/lib/node_modules/pnpm/bin" |
||||
|
PATH = "$JAVA_HOME/bin:$GRADLE_HOME/bin:$MAVEN_HOME/bin:$NODE_HOME/bin:$PNPM_HOME:$HOME/.nvm/versions/node/v20.19.3/bin:$PATH" |
||||
|
} |
||||
|
|
||||
|
stages { |
||||
|
stage('#检查环境') { |
||||
|
steps { |
||||
|
sh """ |
||||
|
node -v |
||||
|
npm config set registry https://registry.npmmirror.com |
||||
|
npm install -g pnpm |
||||
|
pnpm -v |
||||
|
""" |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
stage('#拉取代码') { |
||||
|
steps { |
||||
|
checkout([ |
||||
|
$class : 'GitSCM', |
||||
|
branches : [[name: '*/master']], |
||||
|
userRemoteConfigs: [[url: "${git}", credentialsId: "${gitCredentials}"]], |
||||
|
extensions : [], |
||||
|
]) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
stage('#停止服务') { |
||||
|
steps { |
||||
|
sh """ |
||||
|
pid=`ps -ef | grep "${baseDir}/lcc-work-server/node_modules/" | grep -v 'grep' | awk '{print \$2}'` |
||||
|
if [ -z "\$pid" ];then |
||||
|
echo '${projectName}未运行' |
||||
|
else |
||||
|
ps -ef | grep "${baseDir}/lcc-work-server/node_modules/" | grep -v 'grep' | awk '{print \$2}' | xargs kill |
||||
|
echo '${projectName}已停止!' |
||||
|
sleep 3s |
||||
|
pid=`ps -ef | grep "${baseDir}/lcc-work-server/node_modules/" | grep -v 'grep' | awk '{print \$2}'` |
||||
|
if [ -n "\$pid" ];then |
||||
|
ps -ef | grep "${baseDir}/lcc-work-server/node_modules/" | grep -v 'grep' | awk '{print \$2}' | xargs kill -9 |
||||
|
echo '${projectName}已停止(强制)!' |
||||
|
sleep 1s |
||||
|
fi |
||||
|
fi |
||||
|
""" |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
stage('#编译项目') { |
||||
|
steps { |
||||
|
sh """ |
||||
|
cd $baseDir/lcc-work-server |
||||
|
pnpm i |
||||
|
""" |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
stage('#部署服务') { |
||||
|
steps { |
||||
|
sh """ |
||||
|
pid=`ps -ef | grep "${baseDir}/lcc-work-server/node_modules/" | grep -v 'grep' | awk '{print \$2}'` |
||||
|
if [ -z "\$pid" ];then |
||||
|
echo '${projectName}未运行' |
||||
|
else |
||||
|
ps -ef | grep "${baseDir}/lcc-work-server/node_modules/" | grep -v 'grep' | awk '{print \$2}' | xargs kill |
||||
|
echo '${projectName}已停止!' |
||||
|
sleep 3s |
||||
|
pid=`ps -ef | grep "${baseDir}/lcc-work-server/node_modules/" | grep -v 'grep' | awk '{print \$2}'` |
||||
|
if [ -n "\$pid" ];then |
||||
|
ps -ef | grep "${baseDir}/lcc-work-server/node_modules/" | grep -v 'grep' | awk '{print \$2}' | xargs kill -9 |
||||
|
echo '${projectName}已停止(强制)!' |
||||
|
sleep 1s |
||||
|
fi |
||||
|
fi |
||||
|
""" |
||||
|
withEnv(['JENKINS_NODE_COOKIE=dontkillme']) { |
||||
|
sh """ |
||||
|
cd $baseDir/lcc-work-server |
||||
|
nohup pnpm run dev >> /dev/null 2>&1 & |
||||
|
""" |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue