-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile
54 lines (50 loc) · 1.68 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
pipeline {
environment {
registry = "adi0222/studentSurveyForm"
registryCredential = 'DockerHubCredentials'
TIMESTAMP = new Date().format("yyyy-MM-dd_HH-mm-ss")
KUBECONFIG_CREDENTIALS_ID = 'K8scluster'
DOCKER_IMAGE = "adi0222/studentsurveyform:${env.TIMESTAMP}"
}
agent any
stages {
stage('Build') {
steps {
script{
sh 'rm -rf ../*.war'
dir('src/main/webapp') {
// Specify the path for the war file creation
sh 'jar -cvf ../surveyform.war .'
}
sh 'echo ${BUILD_TIMESTAMP}'
docker.withRegistry('',registryCredential){
def customImage = docker.build("$DOCKER_IMAGE")
}
}
}
}
stage('Push Image to Dockerhub') {
steps {
script{
docker.withRegistry('',registryCredential){
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'
}
}
}
}
}