-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
192 lines (163 loc) · 5.86 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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
def readProperties(){
def properties_file_path = "${workspace}" + "@script/properties.yml"
def property = readYaml file: properties_file_path
env.APP_NAME = property.APP_NAME
env.MS_NAME = property.MS_NAME
env.BRANCH = property.BRANCH
env.GIT_SOURCE_URL = property.GIT_SOURCE_URL
env.SONAR_HOST_URL = property.SONAR_HOST_URL
}
def firstTimeDevDeployment(projectName,msName){
openshift.withCluster() {
openshift.withProject(projectName) {
def bcSelector = openshift.selector( "bc", msName)
def bcExists = bcSelector.exists()
if (!bcExists) {
openshift.newApp("redhat-openjdk18-openshift:1.1~${GIT_SOURCE_URL}","--strategy=source")
sh 'sleep 400'
openshiftTag(namespace: projectName, srcStream: msName, srcTag: 'latest', destStream: msName, destTag: 'test-apps')
openshiftTag(namespace: projectName, srcStream: msName, srcTag: 'latest', destStream: msName, destTag: 'prod-apps')
} else {
sh 'echo build config already exists in development environment'
}
}
}
}
def firstTimeTestDeployment(sourceProjectName,destinationProjectName,msName){
openshift.withCluster() {
openshift.withProject(destinationProjectName){
def dcSelector = openshift.selector( "dc", msName)
def dcExists = dcSelector.exists()
if(!dcExists){
openshift.newApp(sourceProjectName+"/"+msName+":"+"test-apps")
}
else {
sh 'echo deployment config already exists in testing environment'
}
}
}
}
def firstTimeProdDeployment(sourceProjectName,destinationProjectName,msName){
openshift.withCluster() {
openshift.withProject(destinationProjectName){
def dcSelector = openshift.selector( "dc", msName)
def dcExists = dcSelector.exists()
if(!dcExists){
openshift.newApp(sourceProjectName+"/"+msName+":"+"prod-apps")
}
else {
sh 'echo deployment config already exists in production environment'
}
}
}
}
def buildApp(projectName,msName){
openshift.withCluster() {
openshift.withProject(projectName){
openshift.startBuild(msName,"--wait")
}
}
}
def deployApp(projectName,msName){
openshift.withCluster() {
openshift.withProject(projectName){
openshiftDeploy(namespace: projectName,deploymentConfig: msName)
}
}
}
podTemplate(cloud:'openshift',label: 'selenium',
containers: [
containerTemplate(
name: 'jnlp',
image: 'cloudbees/jnlp-slave-with-java-build-tools',
alwaysPullImage: true,
args: '${computer.jnlpmac} ${computer.name}'
)])
{
node
{
def MAVEN_HOME = tool "Maven_HOME"
def JAVA_HOME = tool "JAVA_HOME"
env.PATH="${env.PATH}:${MAVEN_HOME}/bin:${JAVA_HOME}/bin"
stage('First Time Deployment'){
readProperties()
firstTimeDevDeployment("${APP_NAME}-dev-apps", "${MS_NAME}")
firstTimeTestDeployment("${APP_NAME}-dev-apps", "${APP_NAME}-test-apps", "${MS_NAME}")
firstTimeProdDeployment("${APP_NAME}-dev-apps", "${APP_NAME}-prod-apps", "${MS_NAME}")
}
stage('Checkout')
{
checkout([$class: 'GitSCM', branches: [[name: "*/${BRANCH}"]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '', url: "${GIT_SOURCE_URL}"]]])
}
stage('Initial Setup')
{
sh 'mvn clean compile'
}
stage('Code Quality Analysis')
{
sh 'mvn sonar:sonar -Dsonar.host.url="${SONAR_HOST_URL}"'
}
stage('Unit Testing')
{
sh 'chmod 777 ./mvnw'
sh './mvnw test'
}
stage('Code Coverage')
{
sh 'mvn package'
jacoco(deltaBranchCoverage: '10', deltaClassCoverage: '10', deltaComplexityCoverage: '10', deltaInstructionCoverage: '10', deltaLineCoverage: '10', deltaMethodCoverage: '20')
}
stage('Security Scanning')
{
sh 'mvn findbugs:findbugs'
}
/* stage('Dev - Build Application')
{
buildApp("${APP_NAME}-dev-apps", "${MS_NAME}")
}*/
stage('Dev - Deploy Application')
{
deployApp("${APP_NAME}-dev-apps", "${MS_NAME}")
sh script: $/
oc patch deploymentconfig ${MS_NAME} -p '{"spec":{"template":{"metadata":{"annotations":{"sidecar.istio.io/inject": "true"}}}}}' -n=${APP_NAME}-dev-apps
/$
}
stage('Tagging Image for Testing')
{
openshiftTag(namespace: '$APP_NAME-dev-apps', srcStream: '$MS_NAME', srcTag: 'latest', destStream: '$MS_NAME', destTag: 'test-apps')
}
stage('Test - Deploy Application')
{
deployApp("${APP_NAME}-test-apps", "${MS_NAME}")
sh script: $/
oc patch deploymentconfig ${MS_NAME} -p '{"spec":{"template":{"metadata":{"annotations":{"sidecar.istio.io/inject": "true"}}}}}' -n=${APP_NAME}-test-apps
/$
}
node('selenium')
{
stage('Integration Testing')
{
container('jnlp')
{
checkout([$class: 'GitSCM', branches: [[name: "*/${BRANCH}"]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '', url: "${GIT_SOURCE_URL}"]]])
sh 'mvn integration-test'
}
}
}
stage('Tagging Image for Testing')
{
openshiftTag(namespace: '$APP_NAME-dev-apps', srcStream: '$MS_NAME', srcTag: 'latest', destStream: '$MS_NAME', destTag: 'prod-apps')
}
stage('Deploy to Production approval')
{
input "Deploy to Production Environment?"
}
stage('Prod - Deploy Application')
{
deployApp("${APP_NAME}-prod-apps", "${MS_NAME}")
sh script: $/
oc patch deploymentconfig ${MS_NAME} -p '{"spec":{"template":{"metadata":{"annotations":{"sidecar.istio.io/inject": "true"}}}}}' -n=${APP_NAME}-prod-apps
/$
}
}
}