Files
django-vue3-admin/web/Jenkinsfile
T

75 lines
2.2 KiB
Groovy

pipeline {
agent any
environment {
HARBOR_URL = '192.168.80.90:8090'
HARBOR_PROJECT = 'pis'
IMAGE_NAME = 'pis-web'
CREDENTIALS_ID = 'harbor-credentials'
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Install & Build') {
steps {
sh """
cd web
# 安装 Node.js 和 yarn (如果不存在)
if ! command -v yarn &> /dev/null; then
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt-get install -y nodejs
npm install -g yarn
fi
yarn install --registry=https://registry.npmmirror.com
yarn build
"""
}
}
stage('Build Image') {
steps {
script {
def imageTag = "${HARBOR_URL}/${HARBOR_PROJECT}/${IMAGE_NAME}:${BUILD_NUMBER}"
env.IMAGE_TAG = imageTag
sh """
docker build -f docker_env/web/Dockerfile \
-t ${imageTag} .
"""
}
}
}
stage('Push to Harbor') {
steps {
script {
withCredentials([usernamePassword(
credentialsId: CREDENTIALS_ID,
usernameVariable: 'HARBOR_USER',
passwordVariable: 'HARBOR_PASS'
)]) {
sh """
echo ${HARBOR_PASS} | docker login ${HARBOR_URL} -u ${HARBOR_USER} --password-stdin
docker push ${IMAGE_TAG} || true
docker logout ${HARBOR_URL}
"""
}
}
}
}
}
post {
failure {
echo "Frontend Pipeline failed! Check Jenkins logs."
}
success {
echo "Frontend image pushed to Harbor: ${IMAGE_TAG}"
}
}
}