You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
121 lines
4.7 KiB
121 lines
4.7 KiB
//file:noinspection ALL
|
|
pipeline {
|
|
agent any
|
|
|
|
environment {
|
|
projectName = 'logistic-front'
|
|
// 源码配置
|
|
gitCredentials = '98b675d5-b623-4b76-85eb-28a6ed865100'
|
|
// 构建配置
|
|
baseDir = "${WORKSPACE}/"
|
|
dockerImgTag = "$projectName:v$BUILD_NUMBER"
|
|
dockerfileTarget = 'test'
|
|
// harbor配置
|
|
harborProtocol = 'https://'
|
|
harborIP = 'swr.cn-east-3.myhuaweicloud.com'
|
|
harborCredentials = credentials('6de05cdf-c772-4658-8e15-94aec51283cd')
|
|
harborRepositorie = 'wlyc-dev'
|
|
// 部署配置
|
|
imagePullSecrets = 'hw-swr-auth'
|
|
k8sNamespace = 'nanyao'
|
|
containerPort = '8080'
|
|
nodePort = 'false'
|
|
logging = 'enable'
|
|
// 自定义环境变量
|
|
JAVA_HOME = "/usr/local/jdk1.8.0_321"
|
|
NODE_HOME = "/usr/local/node-v14.20.1-linux-x64"
|
|
PATH = "$JAVA_HOME/bin:$NODE_HOME/bin:$PATH"
|
|
}
|
|
|
|
stages {
|
|
stage('#检查环境') {
|
|
steps {
|
|
sh """
|
|
java -version
|
|
node -v
|
|
helm version
|
|
"""
|
|
}
|
|
}
|
|
|
|
stage('#拉取代码') {
|
|
steps {
|
|
checkout([
|
|
$class : 'GitSCM',
|
|
branches : [[name: '*/main']],
|
|
userRemoteConfigs: [[url: "https://code.50yc.com/yypt/logistic-master.git", credentialsId: "${gitCredentials}"]],
|
|
extensions : [[$class: 'RelativeTargetDirectory', relativeTargetDir: './']],
|
|
])
|
|
}
|
|
}
|
|
|
|
stage('#编译项目') {
|
|
steps {
|
|
sh """
|
|
npm config set registry https://registry.npmjs.org/
|
|
yarn config set registry https://registry.npmjs.org/ -g
|
|
cd $baseDir
|
|
cd front/public/yvan-ui
|
|
git pull
|
|
cd $baseDir
|
|
cp -r front/public/yvan-ui/ front/node_modules/
|
|
cp -r front/node_modules/yvan-ui/dist/js/ front/public/
|
|
cd $baseDir
|
|
cd front
|
|
ls -hl
|
|
ls -hl public
|
|
ls -hl public/yvan-ui
|
|
ls -hl node_modules
|
|
ls -hl node_modules/yvan-ui
|
|
"""
|
|
}
|
|
}
|
|
|
|
stage('#构建镜像') {
|
|
steps {
|
|
sh """
|
|
cd $baseDir
|
|
pwd
|
|
sudo docker build -f ./Dockerfile-logistic-front --target $dockerfileTarget -t $dockerImgTag $baseDir
|
|
"""
|
|
}
|
|
}
|
|
|
|
stage('#推送镜像') {
|
|
steps {
|
|
sh 'sudo docker login --username $harborCredentials_USR --password $harborCredentials_PSW $harborProtocol$harborIP'
|
|
sh "sudo docker tag $dockerImgTag $harborIP/$harborRepositorie/$dockerImgTag"
|
|
sh "sudo docker push $harborIP/$harborRepositorie/$dockerImgTag"
|
|
sh "sudo docker rmi $harborIP/$harborRepositorie/$dockerImgTag"
|
|
sh "sudo docker rmi $dockerImgTag"
|
|
}
|
|
}
|
|
|
|
stage('#部署服务') {
|
|
steps {
|
|
sh """
|
|
helm repo add lizw-repo https://gitee.com/LiZhiW/helm-chart/raw/master
|
|
helm repo update lizw-repo
|
|
"""
|
|
script {
|
|
def deployCMD = new StringBuilder()
|
|
deployCMD.append("helm upgrade --install $projectName lizw-repo/node01")
|
|
deployCMD.append(" --namespace $k8sNamespace --create-namespace")
|
|
deployCMD.append(" --version 0.0.1")
|
|
deployCMD.append(" --set env.CMD_PARAMS=''")
|
|
deployCMD.append(" --set image='$harborIP/$harborRepositorie/$dockerImgTag'")
|
|
deployCMD.append(" --set imagePullSecrets='$imagePullSecrets'")
|
|
deployCMD.append(" --set containerPort='$containerPort'")
|
|
deployCMD.append(" --set nodePort='$nodePort'")
|
|
deployCMD.append(" --set labels.logging=$logging")
|
|
//deployCMD.append(" --set nodeSelector.enable='true'")
|
|
//deployCMD.append(" --set nodeSelector.values\\[0\\]='master1'")
|
|
//deployCMD.append(" --set nodeSelector.values\\[1\\]='worker1'")
|
|
deployCMD.append(" --set livenessProbe.initialDelaySeconds='10'")
|
|
deployCMD.append(" --set readinessProbe.initialDelaySeconds='10'")
|
|
sh deployCMD.toString()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|