tmerclub-doc/devops指南/jenkinsfile/mall4cloud-platform-vue-release.jenkinsfile
2025-03-19 15:04:57 +08:00

58 lines
2.3 KiB
Plaintext
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
environment {
// git账号不用改
GIT_CREDENTIAL_ID = '175776d4-6bbc-4da1-ace2-f2a89453fba4'
// git地址
GIT_ADDRESS = 'https://git.mall4j.com/mall4cloud/mall4cloud-platform'
// git分支
GIT_BRANCH = 'master'
// harbor账号不用改
HARBOR_CREDENTIAL_ID = 'edd44d2d-f182-40ab-8e72-b4fcae6f793f'
// harbor地址
HARBOR_ADDR = '192.168.1.11:80'
// 名命空间
NAMESPACE = 'mall4cloud-release'
}
stages {
stage ('拉取git仓库代码') {
steps {
checkout([$class: 'GitSCM', branches: [[name: '*/' + "$GIT_BRANCH"]], extensions: [], userRemoteConfigs: [[credentialsId: "$GIT_CREDENTIAL_ID", url: "$GIT_ADDRESS"]]])
}
}
stage ('通过npm构建项目') {
steps {
sh '''export PATH=/var/jenkins_home/nodejs/bin:$PATH
rm -f .env.production
tee ./.env.production <<-'EOF'
// api接口请求地址
VITE_APP_BASE_API = 'https://cloud-api.mall4j.com'
// 客服webstock接口请求地址 如果是ip的话用 wswss对应的是https
VITE_APP_WEBSOCKET_URL = 'wss://cloud-api.mall4j.com'
VITE_APP_RESOURCES_URL = 'https://mall4j-minio.mall4j.com/mall4cloud'
EOF
sed -i "s#cloud-platform.mall4j.com#cloud-platform.mall4j.com#g" nginx.conf
npm config set registry https://registry.npmmirror.com
pnpm install --no-frozen-lockfile
pnpm run build'''
}
}
stage('构建mall4cloud-platform-vue镜像') {
steps {
withEnv(["PROJECT_NAME=mall4cloud-platform-vue"]) {
sh 'docker build -t $HARBOR_ADDR/$NAMESPACE/$PROJECT_NAME:$BUILD_NUMBER .'
withCredentials([usernamePassword(passwordVariable : 'DOCKER_PASSWORD' ,usernameVariable : 'DOCKER_USERNAME' ,credentialsId : "$HARBOR_CREDENTIAL_ID" ,)]) {
sh 'echo "$DOCKER_PASSWORD" | docker login $HARBOR_ADDR -u "$DOCKER_USERNAME" --password-stdin'
sh 'docker push $HARBOR_ADDR/$NAMESPACE/$PROJECT_NAME:$BUILD_NUMBER'
sh 'ssh root@192.168.1.5 kubectl set image deploy/$PROJECT_NAME $PROJECT_NAME=$HARBOR_ADDR/$NAMESPACE/$PROJECT_NAME:$BUILD_NUMBER -n $NAMESPACE'
}
}
}
}
}
}