-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
91 lines (66 loc) · 2.62 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
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
node {
def project = 'GCP-PROJECT'
def appName = 'gceme'
def feSvcName = "${appName}-frontend"
def imageTag = "gcr.io/${project}/${appName}:${env.BRANCH_NAME}.${env.BUILD_NUMBER}"
// Kube Config
def gcloud = '/var/lib/jenkins/google-cloud-sdk/bin/gcloud'
def kubectl = '/var/lib/jenkins/google-cloud-sdk/bin/kubectl'
def cluster = 'CLUSTER-NAME'
def zone = 'us-central1-b'
checkout scm
//stage 'Run Go tests'
//sh("docker run ${imageTag} go test")
stage('GET Kubernetes get-credentials') {
// some block
sh("${gcloud} container clusters get-credentials ${cluster} --zone ${zone}")
}
//stage 'GET cluster info'
//sh("${gcloud} --configuration=default container clusters list")
stage('GET cluster info') {
// some block
sh("${gcloud} --configuration=default container clusters list")
}
stage "Deploy Application"
switch (env.BRANCH_NAME) {
// Roll out to canary environment
case "canary":
//stage "Build docker image :: ${env.BRANCH_NAME} : ${imageTag}"
stage("Build docker image :: ${env.BRANCH_NAME} : ${imageTag}"){
sh("docker build -t ${imageTag} .")
}
//stage 'Push image to registry'
stage('Push image to registry') {
sh("${gcloud} docker -- push ${imageTag}")
}
// Change deployed image in canary to the one we just built
sh("sed -i.bak 's#gcr.io/cloud-solutions-images/gceme:1.0.0#${imageTag}#' ./k8s/canary/*.yaml")
stage("Kubernetes Deployment : ${env.BRANCH_NAME}"){
sh("${kubectl} --namespace=production apply -f k8s/canary/")
}
break
// Roll out to production
case "master":
/*echo "Build docker image :: ${env.BRANCH_NAME} : ${imageTag}"
//sh("docker build -t ${imageTag} .")
stage 'Push image to registry'
sh("${gcloud} docker -- push ${imageTag}")
*/
stage("Build docker image :: ${env.BRANCH_NAME} : ${imageTag}"){
sh("docker build -t ${imageTag} .")
}
//stage 'Push image to registry'
stage('Push image to registry') {
sh("${gcloud} docker -- push ${imageTag}")
}
// Change deployed image in canary to the one we just built
sh("sed -i.bak 's#gcr.io/cloud-solutions-images/gceme:1.0.0#${imageTag}#' ./k8s/production/*.yaml")
stage("Kubernetes Deployment : ${env.BRANCH_NAME}"){
sh("${kubectl} --namespace=production apply -f k8s/production/")
}
break
// Roll out for other BRANCH_NAME
default:
echo "Deployment came for non-(canary | production) : ${env.BRANCH_NAME}"
}
}