-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
72 lines (69 loc) · 1.61 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
def project = 'dummy-233720'
def appName = 'sample-app'
def imageTag = "gcr.io/${project}/${appName}:${env.BRANCH_NAME}.${env.BUILD_NUMBER}"
pipeline {
agent {
kubernetes {
label 'sample-app'
defaultContainer 'jnlp'
yaml """
apiVersion: v1
kind: Pod
metadata:
labels:
component: ci
spec:
# Use service account that can deploy to all namespaces
serviceAccountName: cicd-jenkins
containers:
- name: gcloud
image: gcr.io/cloud-builders/gcloud
command:
- cat
tty: true
- name: kubectl
image: gcr.io/cloud-builders/kubectl
command:
- cat
tty: true
- name: helm
image: alpine/helm
command:
- cat
tty: true
"""
}
}
stages {
stage('Build and push image with Container Builder') {
steps {
container('gcloud') {
sh "PYTHONUNBUFFERED=1 gcloud builds submit -t ${imageTag} ."
}
}
}
stage('Deploy Production') {
when { branch 'master' }
steps{
container('helm') {
sh("echo prod")
sh("helm version")
}
}
}
stage('Deploy Dev') {
when {
not { branch 'master' }
}
steps {
container('kubectl') {
sh("kubectl get ns ${env.BRANCH_NAME} || kubectl create ns ${env.BRANCH_NAME}")
}
container('helm') {
sh("helm version")
sh(" helm upgrade --install --namespace=${env.BRANCH_NAME} --set image.repository=gcr.io/${project}/${appName} --set image.tag=${env.BRANCH_NAME}.${env.BUILD_NUMBER} sampleapp-${env.BRANCH_NAME} ./helm/sampleapp-chart --wait")
}
}
}
}
}