-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
59 lines (58 loc) · 2.21 KB
/
Copy pathJenkinsfile
File metadata and controls
59 lines (58 loc) · 2.21 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
def app_name = 'sunsten-frontend'
def container_name = 'sunsten-app'
def namespace = 'sunsten'
def docker_rep_app = "${env.DOCKER_SUNSTEN_REPOSITORY}/${app_name}"
def docker_image_tag = "${docker_rep_app}:v${env.BUILD_NUMBER}"
def docker_image_tag_latest = "${env.DOCKER_SUNSTEN_REPOSITORY}/${app_name}:latest"
pipeline {
agent any
stages {
stage('Checkout github') {
steps {
checkout scm
}
}
stage('Build Docker Image') {
steps {
container('docker') {
sh "docker build -t ${docker_image_tag} ."
}
}
}
stage('Push Docker Image') {
steps {
container('docker') {
withCredentials([[$class: 'UsernamePasswordMultiBinding',
credentialsId: env.DOCKER_SUNSTEN_CREDENTIALS_ID,
usernameVariable: 'DOCKER_HUB_USER',
passwordVariable: 'DOCKER_HUB_PASSWORD']]) {
sh """
docker login -u ${DOCKER_HUB_USER} -p ${DOCKER_HUB_PASSWORD}
docker push ${docker_image_tag}
docker tag ${docker_image_tag} ${docker_image_tag_latest}
docker push ${docker_image_tag_latest}
"""
}
}
}
}
stage('Deploy/Update to kubernetes') {
steps {
container('kubectl') {
sh 'echo GETTING PODSI'
withKubeConfig([credentialsId: env.K8s_CREDENTIALS_ID, serverUrl: env.K8s_SERVER_URL, namespace: "${namespace}"]) {
dir('./kubernetes') {
sh 'kubectl get pods'
sh 'for file in *.yml; do kubectl apply -f $file; done'
// sh 'kubectl apply -f frontend-deployment.yml'
// sh 'kubectl apply -f frontend-service.yml'
sh "kubectl rollout restart deployment/${app_name}"
// sh "kubectl set image deployment/${app_name} ${container_name}=${docker_image_tag}"
// sh "kubectl apply -f ingress.yml"
}
}
}
}
}
}
}