-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJenkinsfile
More file actions
125 lines (105 loc) · 3.43 KB
/
Copy pathJenkinsfile
File metadata and controls
125 lines (105 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
pipeline {
agent {
kubernetes {
inheritFrom 'nodejs bare'
containerTemplate {
name 'nodejs'
image '127.0.0.1/library/jdk17-nodes:v1.1.1'
}
}
}
stages {
stage('环境验证') {
steps {
container('nodejs') {
sh '''
echo "===== 环境信息 ====="
echo "Node.js: $(node --version)"
echo "npm: $(npm --version)"
echo "pnpm: $(pnpm --version)"
'''
}
}
}
stage('拉取代码') {
steps {
container('nodejs') {
git(url: 'https://gitee.com/synap-xnet/xnet-mlops-web.git', credentialsId: 'gitee-synap-xnet-id', branch: 'master', changelog: true, poll: false)
}
}
}
stage('安装依赖') {
steps {
container('nodejs') {
sh 'npm config set registry https://registry.npmmirror.com'
sh 'npm install pnpm -g'
sh 'pnpm install'
}
}
}
stage('构建核心依赖') {
steps {
container('nodejs') {
sh 'pnpm run build --filter @vben-core/design'
sh 'pnpm run build --filter @vben-core/shared'
sh 'pnpm run build --filter @vben-core/typings'
}
}
}
stage('构建应用') {
steps {
container('nodejs') {
sh 'pnpm run build --filter @vben/web-antd'
}
}
}
stage('构建并推送镜像') {
agent none
steps {
container('nodejs') {
withCredentials([usernamePassword(credentialsId: 'docker-registry-creds', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
script {
sh 'podman --version || { echo "Podman is not installed"; exit 1; }'
sh '''
echo "$DOCKER_PASS" | podman login http://127.0.0.1 -u "$DOCKER_USER" --password-stdin || { echo "Login failed"; exit 1; }
'''
sh """
podman build -f Dockerfile -t 127.0.0.1/library/xnet-mlops-web:${env.BUILD_NUMBER} . || { echo "Build failed"; exit 1; }
"""
sh """
podman push 127.0.0.1/library/xnet-mlops-web:${env.BUILD_NUMBER} || { echo "Push failed"; exit 1; }
"""
}
}
}
}
}
stage('发布到环境') {
agent none
steps {
container('nodejs') {
withCredentials([kubeconfigContent(credentialsId: 'kube-secret', variable: 'KUBE_CONFIG')]) {
sh '''
mkdir -p ~/.kube
echo "$KUBE_CONFIG" > ~/.kube/config
chmod 600 ~/.kube/config
kubectl version --client
kubectl get nodes -n xnet-mlops || { echo "Failed to connect to Kubernetes cluster"; exit 1; }
sed -i "s|image: 127.0.0.1/library/xnet-mlops-web:.*|image: 127.0.0.1/library/xnet-mlops-web:${BUILD_NUMBER}|" deploy/deploy.yaml
kubectl apply -f deploy/deploy.yaml -n xnet-mlops || { echo "Failed to apply deploy.yaml"; exit 1; }
kubectl rollout restart deployment xnet-mlops-web-deployment -n xnet-mlops || { echo "Failed to restart deployment"; exit 1; }
'''
}
}
}
}
stage('归档制品') {
steps {
container('nodejs') {
sh 'cd apps/web-antd && tar -czf dist.tar.gz dist/'
}
archiveArtifacts(artifacts: 'apps/web-antd/dist.tar.gz', fingerprint: true, onlyIfSuccessful: true)
}
}
}
}