-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
78 lines (70 loc) · 1.96 KB
/
Jenkinsfile
File metadata and controls
78 lines (70 loc) · 1.96 KB
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
pipeline {
agent any
parameters {
string(name: 'Container', defaultValue: 'todoapp', description: 'Container name')
string(name: 'Image', defaultValue: 'todoapp:latest', description: 'Image name and tag')
string(name: 'Repo', defaultValue: 'tutug', description: 'Reporitory url')
string(name: 'FrontendImage', defaultValue: 'todoapp-fd:latest', 'Image name of frontend app')
}
stages {
stage('Cloning Git') {
steps {
checkout scm
}
}
stage('Install dependencie') {
steps {
sh 'npm install'
}
}
stage('Test') {
steps {
sh 'npm test'
}
}
stage('Remove older image') {
steps {
sh "docker rmi -f ${params.Repo}/${params.Image} || true"
}
}
stage('Build docker image') {
steps {
echo env.JWT_SECRET
sh """docker build \
--build-arg JWT_SECRET=${env.JWT_SECRET} \
--build-arg PORT=${env.PORT} \
--build-arg API_URL=${env.API_URL} \
-t ${params.Repo}/${params.Image} ."""
}
}
stage('Push image to registry') {
steps {
sh "docker push ${params.Repo}/${params.Image}"
}
}
stage('Deploy') {
steps {
// sh "docker container stop ${params.Container} || true"
// sh "docker container rm ${params.Container} || true"
sh "kubectl apply -f k8s"
// sh "docker run -d -p 3005:3005 --name ${params.Container} ${params.Repo}/${params.Image}"
echo "Successfully build ${env.BUILD_ID} on ${env.JENKINS_URL}"
}
}
}
stage('Build frontend image') {
steps {
echo env.JWT_SECRET
HOST=$(minikube ip)
PORT
sh """docker build \
--build-arg API_URL=http://${HOST}:${PORT}/api \
-t ${params.Repo}/${params.FrontendImage} ."""
}
}
stage('Push frontend image to registry') {
steps {
sh "docker push ${params.Repo}/${params.FrontendImage}"
}
}
}