upload-to-gcs
- 配置一个
服务账号
,配置操作Cloud Storage的权限
,创建密钥
并保存命名空间kubesphere-devops-worker
中的配置字典dokimet-gcloud-config
里面; - 下载
google-cloud-cli-436.0.0-linux-x86_64.tar.gz
并保存在命名空间kubesphere-devops-worker
中的pvcdokimet-google-data-pvc
里面; - 创建存储桶
game.birenchong.cn
,在权限
中给allUsers
分配Storage Object Viewer
角色;
# Jenkinsfile
pipeline {
agent {
kubernetes {
label 'cocos'
yaml '''apiVersion: v1
kind: Pod
spec:
containers:
- name: "base"
image: "kubesphere/builder-python:v3.2.0"
command: [\'cat\']
tty: true
volumeMounts:
- mountPath: "/home/jenkins/google"
name: "google-data-volume"
readOnly: false
- mountPath: "/home/jenkins/send_dingding.sh"
name: "dingding-script-volume"
subPath: "send_dingding.sh"
- mountPath: "/root/.google/config.json"
name: "config-volume"
subPath: "config.json"
- mountPath: "/var/run/docker.sock"
name: "volume-0"
readOnly: false
- mountPath: "/home/jenkins/agent"
name: "workspace-volume"
readOnly: false
nodeSelector:
env-devops: 'true'
volumes:
- name: "google-data-volume"
persistentVolumeClaim:
claimName: "birenchong-google-data-pvc"
- hostPath:
path: "/var/run/docker.sock"
name: "volume-0"
- emptyDir:
medium: ""
name: "workspace-volume"
- configMap:
items:
- key: "charged-atlas-35xxx7-ca2xxxxxxxxx3.json"
path: "config.json"
name: "birenchong-gcloud-config"
name: "config-volume"
- configMap:
items:
- key: "send_dingding.sh"
path: "send_dingding.sh"
name: "birenchong-jenkins-dingding-script"
name: "dingding-script-volume"
'''
}
}
stages {
stage('配置google凭证') {
agent none
steps {
container('base') {
sh 'cp /home/jenkins/google/google-cloud-cli-436.0.0-linux-x86_64.tar.gz .'
sh 'tar -xf google-cloud-cli-436.0.0-linux-x86_64.tar.gz'
sh './google-cloud-sdk/install.sh -q'
sh './google-cloud-sdk/bin/gcloud auth activate-service-account --key-file=/root/.google/config.json'
}
}
}
stage('推送到gs') {
agent none
steps {
container('base') {
sh 'mv build/web-mobile/index.html build/web-mobile/index-${BUILD_NUMBER}.html'
sh './google-cloud-sdk/bin/gsutil cp -r build/web-mobile/* gs://game.birenchong.cn/${APP_NAME}/${BRANCH_NAME}/'
}
}
}
}
environment {
APP_NAME = 'birenchong'
}
post {
success {
container('base') {
sh 'bash /home/jenkins/send_dingding.sh "构建成功" "https://game.birenchong.cn/${APP_NAME}/${BRANCH_NAME}/index-${BUILD_NUMBER}.html"'
}
}
failure {
container('base') {
sh 'bash /home/jenkins/send_dingding.sh "构建失败"'
}
}
aborted {
container('base') {
sh 'bash /home/jenkins/send_dingding.sh "取消构建"'
}
}
}
}
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
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
Last Updated: 2023/11/08, 14:45:54