-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
96 lines (81 loc) · 3.39 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
92
93
94
95
node {
try {
isTag = (env.TAG_NAME != null)
if ( !(env.BRANCH_NAME =~ /(dev|master|PR-)/) && !isTag ){
// Only Build PRs, Dev, and Master and tags, don't build on branch push
echo "Not master, dev, PR-*, or tag so not building"
currentBuild.result = 'SUCCESS'
return
}
def projectName = "marketing-website"
def container
def imageTag
def branchTag
def slidingTag
stage('Clone repository') {
step([$class: 'WsCleanup'])
checkout scm
}
stage('Build') {
if (env.BRANCH_NAME == 'dev') {
slidingTag = "dev"
}
else if (env.BRANCH_NAME == 'master') {
slidingTag = "master"
}
else if (isTag) {
slidingTag = "production"
}
if (env.BRANCH_NAME == 'master' || env.BRANCH_NAME == 'dev'|| isTag){
def branchReplaced = env.BRANCH_NAME.toLowerCase().replaceAll("\\/", "-")
branchTag = "gcr.io/featurepeek-build/${projectName}:${slidingTag}"
imageTag = "gcr.io/featurepeek-build/${projectName}:${branchReplaced}-${env.BUILD_ID}"
def secret_addition = ""
if (!isTag){
secret_addition = "_DEV"
}
withCredentials([
string(credentialsId: "MAILCHIMP_API_KEY${secret_addition}", variable: 'MAILCHIMP_API_KEY'),
string(credentialsId: "MAILCHIMP_DOMAIN${secret_addition}", variable: 'MAILCHIMP_DOMAIN'),
string(credentialsId: "MAILCHIMP_FORM_ID${secret_addition}", variable: 'MAILCHIMP_FORM_ID'),
string(credentialsId: "MAILCHIMP_LIST_ID${secret_addition}", variable: 'MAILCHIMP_LIST_ID'),
string(credentialsId: "SEGMENT_ID${secret_addition}", variable: 'SEGMENT_ID'),
string(credentialsId: "STRIPE_SECRET_KEY${secret_addition}", variable: 'STRIPE_SECRET_KEY')]){
sh 'env > .env.production'
container = docker.build(imageTag, ".")
sh 'rm .env.production'
}
}
}
stage('push to gcr.io') {
if (env.BRANCH_NAME == 'master' || env.BRANCH_NAME == 'dev' || isTag) {
sh "docker tag ${imageTag} ${branchTag}"
sh "gcloud docker -- push ${imageTag}"
sh "gcloud docker -- push ${branchTag}"
}
}
stage('deploy') {
milestone()
if (env.BRANCH_NAME == 'dev'){
echo 'Getting Kube context for dev cluster'
sh "gcloud container clusters get-credentials primary --zone us-central1-a --project featurepeek-dev"
}
else if (env.BRANCH_NAME == 'master'){
echo 'Getting Kube context for stable cluster'
sh "gcloud container clusters get-credentials primary --zone us-central1-a --project featurepeek-stable"
}
else if (isTag){
echo 'Getting Kube context for production cluster'
sh "gcloud container clusters get-credentials primary --zone us-central1-a --project featurepeek-production"
}
sh "kubectl set image deployment/${projectName} ${projectName}=${imageTag}"
}
} catch (e) {
// If there was an exception thrown, the build failed
currentBuild.result = "FAILED"
throw e
} finally {
// Success or failure, always send notifications
// notifyBuild(currentBuild.result)
}
}