-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
57 lines (51 loc) · 1.91 KB
/
Jenkinsfile
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
def createVersion() {
// 定义一个版本号作为当次构建的版本,输出结果 20191210175842_69
return new Date().format('yyyyMMddHHmmss') + "_${env.BUILD_ID}"
}
pipeline {
agent {
label 'k8s-node'
}
environment {
gitlab_id = "438e5486-9fac-4cb8-8351-2951c8d42790"
gitlab_repo = "http://192.168.50.182:31001/wx/pages.git"
docker_id = "a83a4d6c-3b91-4717-a1c3-23f519c1aced"
docker_registory = "192.168.50.182:30082"
docker_repo = "gssjl2008"
image_name = "pages"
image_version = createVersion()
kube_yaml = "pages.yaml"
kube_ns = "default"
}
stages {
stage("代码检出"){
steps{
git credentialsId: gitlab_id, url: gitlab_repo
}
}
stage("打包"){
steps{
withCredentials([usernamePassword(credentialsId: gitlab_id, passwordVariable: 'password', usernameVariable: 'username')]) {
sh """
echo y | docker system prune -a
docker build -t ${docker_registory}/${docker_repo}/${image_name}:${image_version} .
docker login ${docker_registory} -u ${username} -p ${password}
docker tag ${docker_registory}/${docker_repo}/${image_name}:${image_version} ${docker_registory}/${docker_repo}/${image_name}:latest
docker push ${docker_registory}/${docker_repo}/${image_name}:latest
kubectl get pod -n jenkins
"""
}
}
}
stage("部署"){
steps{
timeout(time: 60, unit: 'SECONDS') {
sh """
kubectl delete -f ${kube_yaml} -n ${kube_ns} || echo "First deploy in k8s"
kubectl apply -f ${kube_yaml} -n ${kube_ns}
"""
}
}
}
}
}