Files
JuiceWorkStation/Jenkinsfile
T

113 lines
2.2 KiB
Groovy

pipeline {
agent any
tools {
nodejs 'nodejs'
}
environment {
DEPLOY_DIR = '/opt/1panel/www/sites/workstation.xiaozhou233.cn/index'
}
options {
timestamps()
disableConcurrentBuilds()
buildDiscarder(
logRotator(
numToKeepStr: '10',
artifactNumToKeepStr: '5'
)
)
}
stages {
stage('Checkout') {
steps {
cleanWs()
checkout scm
}
}
stage('Install') {
steps {
// Install frontend dependencies
dir('dashboard') {
sh 'npm ci'
}
}
}
stage('Build') {
steps {
// Build frontend
dir('dashboard') {
sh 'npm run build'
}
}
}
stage('Version') {
steps {
dir('dashboard') {
sh '''
cat > dist/version.json <<EOF
{
"buildNumber": "${BUILD_NUMBER}",
"commit": "$(git rev-parse --short HEAD)",
"branch": "${GIT_BRANCH}",
"time": "$(date '+%Y-%m-%d %H:%M:%S')"
}
EOF
'''
}
}
}
stage('Package') {
steps {
// Package frontend
sh 'zip -r dashboard.zip dashboard/dist'
}
}
stage('Build Backend Image') {
steps {
// Build backend Docker image
sh 'docker build -t workstation-server:${BUILD_NUMBER} backend/'
}
}
stage('Deploy') {
steps {
sh '''
echo "Deploying to ${DEPLOY_DIR}"
mkdir -p ${DEPLOY_DIR}
rsync -av --delete dashboard/dist/ ${DEPLOY_DIR}/
echo "Deploy completed"
'''
}
}
}
post {
success {
archiveArtifacts artifacts: 'dashboard.zip', fingerprint: true
echo 'Build succeeded'
}
failure {
echo 'Build failed'
}
always {
echo 'Pipeline finished'
}
}
}