-
Notifications
You must be signed in to change notification settings - Fork 7
/
ATGAntBuild.groovy
246 lines (231 loc) · 8.57 KB
/
ATGAntBuild.groovy
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#!groovy
/**
* Function: ATG ANT Builder which will compiles the code, execute unit tests and create packages
* Author: [email protected]
* Date: 24 Apr'2017
*/
package main.com.rocc.stages.impl
import groovy.lang.Closure;
import java.nio.file.*
import groovy.util.AntBuilder.*
/**
* @Function: Load a resource file
* @params: Workspace and path of file
*/
def getProperty( def wspace, def prop) {
try {
def workspace = wspace+"@libs/DevOps/resources/config/account.properties"
echo "Load the file workspace"
Properties props = new Properties()
File propsFile = new File(workspace)
props.load(propsFile.newDataInputStream())
return props
}
catch (Exception groovyEx) {
println groovyEx.getMessage()
println groovyEx.getCause()
throw groovyEx
}
}
/**
* Funtion: Method use to clean the workspace
* @param workspace
*/
def cleanWorkspace( def wspace) {
try {
echo 'Cleaning the workspace'
echo wspace
Properties props = getProperty()
def build_dir = props.getProperty(wspace,"build_dir")
new File(build_dir).deleteDir()
}
catch (Exception groovyEx) {
println groovyEx.getMessage()
println groovyEx.getCause()
throw groovyEx
}
}
/**
* Function: Method used to copy the src/classes directory
* @param workspace
*/
def copy( def wspace) {
try {
echo 'copy code base at workspace'
echo "chopping the string"
def str = wspace[-1..-1]
echo str+'strrrrrrrrrrrrrr'
if (str.isNumber()) {
ws = wspace[0..-3]
echo ws+' neweeeeeeeeeeeeeee'+str
def sourceFolder = ws+"@libs/DevOps/resources/"
echo "source path : $sourceFolder"
file_path = ws+"@libs/DevOps/resources/config/prod_dev_weblogic.properties"
Properties props = new Properties()
File propsFile = new File("$file_path")
props.load(propsFile.newDataInputStream())
def app_path = props.getProperty('module.workspace')
def destFolder = wspace+'/'+"${app_path}"+'/build_scripts'
echo "destination folder: $destFolder"
def script_path=ws+'@libs/DevOps/resources/scripts/download_lib.sh'
def proc="sh $script_path $sourceFolder $destFolder".execute().text
} else {
def sourceFolder1 = wspace+"@libs/DevOps/resources/"
echo "source path : $sourceFolder1"
file_path1 = wspace+"@libs/DevOps/resources/config/prod_dev_weblogic.properties"
Properties props1 = new Properties()
File propsFile1 = new File("$file_path1")
props1.load(propsFile1.newDataInputStream())
def app_path1 = props1.getProperty('module.workspace')
def destFolder1 = wspace+'/'+"${app_path1}"+'/build_scripts'
echo "destination folder: $destFolder1"
def script_path1=wspace+'@libs/DevOps/resources/scripts/download_lib.sh'
def proc1="sh $script_path1 $sourceFolder1 $destFolder1".execute().text
}
//sh(returnStdout: true, script: "")
//def c = new StringBuffer()
//proc.consumeProcessErrorStream(c)
//echo proc.text
//echo c.toString()
}
catch (Exception groovyEx) {
println groovyEx.getMessage()
println groovyEx.getCause()
throw groovyEx
}
}
/**
* Function: Method used to execute the ant build
* @params: workspace, ant home
*/
def execAntBuild( def wspace, def antpath) {
try {
echo "chopping the string"
def str = wspace[-1..-1]
if (str.isNumber()) {
ws = wspace[0..-3]
file_path = ws+"@libs/DevOps/resources/config/prod_dev_weblogic.properties"
} else {
file_path = wspace+"@libs/DevOps/resources/config/prod_dev_weblogic.properties"
}
Properties props = new Properties()
File propsFile = new File("$file_path")
props.load(propsFile.newDataInputStream())
def app_path = props.getProperty('module.workspace')
def build_file = wspace+'/'+"${app_path}"+'/build_scripts/build_weblogic.xml'
echo "Buildfile path : ${build_file}"
def result = sh(returnStdout: true, script: "${antpath}/bin/ant -f $build_file -DdisableUnitTest=true build")
println result
}
catch (Exception groovyEx) {
println groovyEx.getMessage()
println groovyEx.getCause()
throw groovyEx
}
}
/**
* Function: Method used to package the build artifacts
* @params: workspace, instance name, branch name, environment name
*/
def AssembleEAR ( def instance, def env, def wspace, def Instrumented, def branch_name, def ant_path) {
try {
echo "chopping the string"
def str = wspace[-1..-1]
if (str.isNumber()) {
ws = wspace[0..-3]
file_path = ws+"@libs/DevOps/resources/config/${instance}_dev_weblogic.properties"
println file_path
} else {
file_path = wspace+"@libs/DevOps/resources/config/${instance}_dev_weblogic.properties"
}
Properties props = new Properties()
File propsFile = new File("$file_path")
props.load(propsFile.newDataInputStream())
def app_path = props.getProperty('module.workspace')
def build_file = wspace+'/'+"${app_path}"+'/build_scripts/build_weblogic.xml'
echo "Buildfile path : ${build_file}"
echo "JVM: ${instance}"
def result = sh(returnStdout: true, script: "cd $wspace; ${ant_path}/bin/ant -f $build_file -DInstrumented=${Instrumented} -Denv=${env} -Dbranch_name=${branch_name} -Dservername=${instance} -Dear.home=${wspace} deploy-ear-to-weblogic")
println result
}
catch (Exception groovyEx) {
println groovyEx.getMessage()
println groovyEx.getCause()
throw groovyEx
}
}
/**
* Function: Method used to deploy package the build artifacts repository
* @params: workspace, instance name, branch name, environment name
*/
def NexusDeploy( def mvn_home, def wspace, def instance,def buildNumber) {
try {
echo "chopping the string"
echo "Build Number == ${buildNumber}"
def str = wspace[-1..-1]
if (str.isNumber()) {
ws = wspace[0..-3]
file_path = ws+"@libs/DevOps/resources/config/username.properties"
get_nexus_path = ws+"@libs/DevOps/resources/config/account.properties"
} else {
file_path = wspace+"@libs/DevOps/resources/config/username.properties"
get_nexus_path = wspace+"@libs/DevOps/resources/config/account.properties"
}
Properties props = new Properties()
File propsFile = new File("$file_path")
props.load(propsFile.newDataInputStream())
def app_path = props.getProperty('ant.project.name')
Properties props1 = new Properties()
File propsFile1 = new File("$get_nexus_path")
props1.load(propsFile1.newDataInputStream())
def nexus_url = props1.getProperty('nexus')
def result = sh(returnStdout: true, script: "cd ${wspace}/application/${app_path}_${instance}; tar -zcvf ${app_path}_${instance}.ear.tar.gz ${app_path}_${instance}.ear; ${mvn_home}/bin/mvn deploy:deploy-file -DgroupId=${app_path} -DartifactId=${app_path} -Dversion=${buildNumber} -DgeneratePom=true -Dpackaging=tar.gz -DrepositoryId=nexus -Durl=${nexus_url} -Dfile=${app_path}_${instance}.ear.tar.gz")
println result
}
catch (Exception groovyEx) {
println groovyEx.getMessage()
println groovyEx.getCause()
throw groovyEx
}
}
/**
* Function: Method used to deploy package the build artifacts repository
* @params: workspace, instance name, branch name, environment name
*/
def deployment ( def wspace ) {
//def weblogic_home, def ear_name, def wspace, def Instrumented, def branch_name
// yet to be integrated.
try {
def build_file = wspace+'/WebCommerce/rocc/build_scripts/build_weblogic.xml'
echo "Stopping weblogic server "
sh(returnStdout: false, script: "sleep 20")
echo "Starting weblogic server "
def result = sh(returnStdout: true, script: "sleep 20")
echo "Weblogic server restarted"
println result
}
catch (Exception groovyEx) {
println groovyEx.getMessage()
println groovyEx.getCause()
throw groovyEx
}
}
/**
* Function: Method used to deploy package the build artifacts repository
* @params: workspace, instance name, branch name, environment name
*/
def ZapSecurity( def wspace , def ZAP_path) {
//def weblogic_home, def ear_name, def wspace, def Instrumented, def branch_name
try {
def build_file = wspace+'/WebCommerce/rocc/build_scripts/build_weblogic.xml'
def ran = sh(returnStdout: true, script: "head -200 /dev/urandom | cksum | cut -f1 -d ' '")
println ran
def result = sh(returnStdout: true, script: "sh ${ZAP_path}/ZAP_2.6.0/zap.sh -daemon -newsession ${ran} -cmd -quickurl http://del2vmplidoweb01:8081/nexus/content/repositories/rocc -quickprogress -quickout report.xml")
println result
}
catch (Exception groovyEx) {
println groovyEx.getMessage()
println groovyEx.getCause()
throw groovyEx
}
}