forked from gouthamchilakala/PetClinic
-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathJenkinsfile_Container
80 lines (73 loc) · 2.6 KB
/
Jenkinsfile_Container
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
pipeline {
agent any
tools {
maven 'MAVEN3'
jdk 'JAVA8'
}
options {
buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '10')
disableConcurrentBuilds()
timestamps()
}
parameters {
string defaultValue: '', description: 'Version of the java application', name: 'app_version', trim: false
choice choices: ['DEV', 'QA', 'INT', 'PRE_PROD'], description: 'Environment name for the code deployment', name: 'APP_ENV'
}
stages {
stage('Code Checkout'){
steps {
echo "code checkout"
git 'https://github.com/gopishank/PetClinic.git'
}
}
stage('Code Build'){
steps {
sh "mvn test-compile"
}
}
stage('Code Analysis & Unit Tests'){
failFast true
parallel {
stage('Unit test') {
steps {
sh "mvn test"
}
}
stage('SonarQube Scan'){
environment {
SCANNER_HOME = tool 'sonar-scanner'
}
steps {
withSonarQubeEnv (installationName: 'sonarqube') {
sh "${SCANNER_HOME}/bin/sonar-scanner -Dproject.settings=sonar-project.properties"
}
}
}
}
}
stage('Code Package'){
steps {
sh "mvn package"
}
}
stage('Image Build & Upload'){
steps {
sh '''
POM_VERSION=`grep "<version>" pom.xml | head -1 | awk -F "-" '{print $1}' | tail -c 6`
sudo docker image build -t petclinic:${POM_VERSION} .
sudo docker image tag petclinic:${POM_VERSION} gopishankar1/petclinic:${POM_VERSION}
sudo docker image push gopishankar1/petclinic:${POM_VERSION}
'''
}
}
stage('Kubernetes Deployment'){
steps {
echo "Install kubectl command on your Jenkins Server"
echo "Bring the file /etc/kubernetes/admin.conf from your kubernetes Master server and place anywhere in Jenkins"
sh '''
kubectl apply -f /home/ubuntu/kubernetes/petclinic/deployment.yaml --kubeconfig=/home/ubuntu/kubernetes/config/kubeconfig
'''
}
}
}
}