forked from adi-limbekar/SWE-645-Assignment-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
45 lines (40 loc) · 1.45 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
pipeline {
agent any
environment {
DOCKER_IMAGE = "adi0222/surveyformimage:${env.BUILD_ID}"
KUBECONFIG_CREDENTIALS_ID = '5574b1da-9b69-451a-b775-bdf66c5ec6e2'
}
stages {
stage('Build Docker Image') {
steps {
script {
docker.build("$DOCKER_IMAGE")
}
}
}
stage('Push Docker Image') {
steps {
withCredentials([usernamePassword(credentialsId: 'DockerHubCredentials', usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD')]) {
script {
sh "docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD"
sh "docker push $DOCKER_IMAGE"
}
}
}
}
stage('Deploying to Rancher as Load Balancer') {
steps {
withCredentials([file(credentialsId: "$KUBECONFIG_CREDENTIALS_ID", variable: 'KUBECONFIG')]) {
sh 'kubectl set image deployment/surveyformlb container-0=$DOCKER_IMAGE'
}
}
}
stage('Deploying to Rancher as Node Port') {
steps {
withCredentials([file(credentialsId: "$KUBECONFIG_CREDENTIALS_ID", variable: 'KUBECONFIG')]) {
sh 'kubectl set image deployment/surveyformnp container-0=$DOCKER_IMAGE'
}
}
}
}
}