forked from ihopeit/recruitment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
59 lines (55 loc) · 2.3 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
58
59
pipeline {
agent any
stages {
stage('Checkout Source') {
steps {
git url:'https://gitee.com/geektime-geekbang/django.git', branch:'master'
}
}
stage('Docker Build') {
steps {
sh "docker build -t ihopeit/django-recruitment:${env.BUILD_NUMBER} ."
sh "docker tag ihopeit/django-recruitment:${env.BUILD_NUMBER} registry.cn-beijing.aliyuncs.com/ihopeit/django-recruitment:${env.BUILD_NUMBER}"
}
}
stage('Docker Push') {
steps {
withCredentials([usernamePassword(credentialsId: 'aliyunhub', passwordVariable: 'dockerHubPassword', usernameVariable: 'dockerHubUser')]) {
sh "docker login -u ${env.dockerHubUser} -p ${env.dockerHubPassword} registry.cn-beijing.aliyuncs.com"
sh "docker push registry.cn-beijing.aliyuncs.com/ihopeit/django-recruitment:${env.BUILD_NUMBER}"
}
}
}
stage('Docker Remove Image') {
steps {
sh "docker rmi registry.cn-beijing.aliyuncs.com/ihopeit/django-recruitment:${env.BUILD_NUMBER}"
sh "docker rmi ihopeit/django-recruitment:${env.BUILD_NUMBER}"
}
}
stage('Apply Kubernetes Files') {
steps {
// 在 jenkins 的 pipeline 配置中替换掉下面的 caCertificate 的内容
kubeconfig(caCertificate: 'base64-encoded-certificate-authority-data==',credentialsId: 'kubeconfig', serverUrl: 'https://192.168.0.235:6443') {
// 部署到 kubernetes
sh 'echo deploy to kubernetes'
sh 'kubectl apply -f k8s/web-claim0-persistentvolumeclaim.yaml '
sh 'kubectl apply -f k8s/redis-service.yaml'
sh 'kubectl apply -f k8s/flower-service.yaml'
sh 'kubectl apply -f k8s/web-service.yaml'
sh 'kubectl apply -f k8s/redis-deployment.yaml'
sh 'cat k8s/celery-deployment.yaml | sed "s/{{BUILD_NUMBER}}/$BUILD_NUMBER/g" | kubectl apply -f -'
sh 'cat k8s/flower-deployment.yaml | sed "s/{{BUILD_NUMBER}}/$BUILD_NUMBER/g" | kubectl apply -f -'
sh 'cat k8s/web-deployment.yaml | sed "s/{{BUILD_NUMBER}}/$BUILD_NUMBER/g" | kubectl apply -f -'
}
}
}
}
post {
success {
sh "echo Pipeline is successfully completed."
}
failure {
sh "echo Pipeline failed. Please check the logs."
}
}
}