-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
80 lines (78 loc) · 2.97 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
// prerequisites: a nodejs app must be deployed inside a kubernetes cluster
// TODO: look for all instances of [] and replace all instances of
// '[VARIABLE]' with actual values
// e.g https://github.com/SankirthGupta/events-app-web-server.git might become https://github.com/MyName/external.git
// variables:
// https://github.com/SankirthGupta/events-app-web-server.git
// main
// dtc-nov21-user306
// web-server-image
// cnd-cluster-nov
// us-central1-c
// the following values can be found in the yaml:
// demo-ui
// demo-ui (name of the container to be replaced - in the template/spec section of the deployment)
pipeline {
agent none
stages {
stage('Get Source') {
agent {
docker {
image 'node:14-alpine'
args '-e HOME=/tmp -e NPM_CONFIG_PREFIX=/tmp/.npm'
}
}
steps {
echo 'Retrieving source from github'
git branch: 'main',
url: 'https://github.com/SankirthGupta/events-app-web-server.git'
echo 'Did we get the source?'
sh 'ls -a'
}
}
stage('Dependencies') {
agent {
docker {
image 'node:14-alpine'
args '-e HOME=/tmp -e NPM_CONFIG_PREFIX=/tmp/.npm'
}
}
steps {
echo 'install dependencies'
sh 'npm install'
echo 'Run tests'
sh 'npm test'
echo 'Tests passed on to build and deploy Docker container'
}
}
stage('Run Tests') {
agent {
docker {
image 'node:14-alpine'
args '-e HOME=/tmp -e NPM_CONFIG_PREFIX=/tmp/.npm'
}
}
steps {
echo 'Run tests'
sh 'npm test'
echo 'Tests passed on to build and deploy Docker container'
}
}
stage('Build and deploy the container') {
agent {
docker {
image 'google/cloud-sdk:latest'
args '-e HOME=/tmp'
}
}
steps {
echo "submit gcr.io/dtc-nov21-user306/web-server-image:v2.${env.BUILD_ID}"
sh "gcloud builds submit -t gcr.io/dtc-nov21-user306/web-server-image:v2.${env.BUILD_ID} ."
echo 'Get cluster credentials'
sh 'gcloud container clusters get-credentials cnd-cluster-nov --zone us-central1-c --project dtc-nov21-user306'
echo "Update the image to use gcr.io/dtc-nov21-user306/web-server-image:v2.${env.BUILD_ID}"
sh "kubectl set image deployment/demo-ui demo-ui=gcr.io/dtc-nov21-user306/web-server-image:v2.${env.BUILD_ID} --record"
}
}
}
}