forked from SoftwareAG/sagdevops-ci-assets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildDeployer.xml
executable file
·235 lines (201 loc) · 11.1 KB
/
buildDeployer.xml
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
<?xml version="1.0"?>
<project default="bda.deployer.startDeployer" basedir="." name="build_Deployer">
<condition property="isWindows">
<os family="windows" />
</condition>
<condition property="isUnix">
<os family="unix" />
</condition>
<target name="bda.deployer.initWindows" if="isWindows">
<property name="deployerExecutable" value="Deployer.bat" />
<property name="deployerAutomatorExecutable" value="projectautomator.bat" />
</target>
<target name="bda.deployer.initUnix" if="isUnix">
<property name="deployerExecutable" value="Deployer.sh" />
<property name="deployerAutomatorExecutable" value="projectautomatorUnix.sh" />
</target>
<target name="bda.deployer.initDeployer" depends="bda.deployer.cleanup, bda.deployer.initWindows, bda.deployer.initUnix">
<!--
If antcontrib has not been included by parent script already, uncomment these lines...
<taskdef classpathref="bda.classpath" resource="net/sf/antcontrib/antlib.xml" />
<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="bda.classpath" />
-->
<property name="projectName" value="${config.deployer.projectNamePrefix}_${bda.targetEnv}_${bda.projectName}" />
<property name="projectAutomatorDefinition" location="${config.tmpdir}/${projectName}_PA_template.definition.xml" />
<log msg="Init build Deployer. Properties: with project name='${projectName}' and repository='${fbrRepoName}'." />
<log msg="Target Environment='${bda.targetEnv}'" />
<log msg="Project name='${projectName}'" />
<log msg="Repository Name='${fbrRepoName}'." />
<log msg="Repository location='${fbrRepoDir}'" />
</target>
<target name="bda.deployer.createProjectAutomatorTemplate" depends="">
<property name="groovyScript.CreateProjectAutomatorTemplate" location="resources/ProjectAutomator/CreateProjectAutomatorTemplate.groovy" />
<log msg="Creating project definition file '${projectAutomatorDefinition}' using environments defined in '${environmentsDefinition}'. Groovy script: '${groovyScript.CreateProjectAutomatorTemplate}'" />
<log msg="-repoName ${fbrRepoName}"/>
<groovy src="${groovyScript.CreateProjectAutomatorTemplate}">
<arg line="-r '${fbrRepoDir}'" />
<arg line="-p '${projectName}'" />
<arg line="-f '${projectAutomatorDefinition}'" />
<arg line="-t ${bda.targetEnv}" />
<arg line="-d ${config.deployer.deployerHost}:${config.deployer.deployerPort}" />
<arg line="-u ${config.deployer.deployerUsername}" />
<arg line="-s ${config.deployer.deployerPassword}" />
<arg line="-e '${environmentsDefinition}'" />
<arg line="-repoName ${fbrRepoName}" />
<arg line="-splitDeploymentSets ${config.deployer.splitDelpoymentSets}" />
</groovy>
</target>
<target name="bda.deployer.cleanup">
<delete file="${projectAutomatorDefinition}">
</delete>
</target>
<target name="bda.deployer.startDeployer" depends="bda.deployer.setupDeployer, bda.deployer.extractDeploymentCandidates" description="creates the deployer project and invokes Deployer for execution">
</target>
<target name="bda.deployer.setupDeployer" depends="bda.deployer.initDeployer, bda.deployer.createProjectAutomatorTemplate, bda.deployer.execProjectAutomator, bda.deployer.importVarSubs" description="creates the deployer project">
</target>
<target name="bda.deployer.execProjectAutomator">
<path id="path.projectdefinition">
<pathelement location="${projectAutomatorDefinition}" />
</path>
<pathconvert refid="path.projectdefinition" property="path.projectdefinition.file">
</pathconvert>
<property name="output" value="${config.deployer.deployerInstallationPath}/logs/CLI.log" />
<property name="paExec" value="${config.deployer.deployerInstallationPath}/${deployerAutomatorExecutable}"/>
<log msg="Executing ProjectAutomator '${paExec}' with input file '${path.projectdefinition.file}'. Writing output to '${output}'"/>
<exec resultproperty="paResult" failonerror="false" dir="${config.deployer.deployerInstallationPath}" executable="${paExec}" output="${output}">
<arg value="${path.projectdefinition.file}" />
</exec>
<if>
<not>
<equals arg1="${paResult}" arg2="0" />
</not>
<then>
<loadfile property="CLI.log" srcFile="${output}" />
<log msg="Project Automator returned an error. Output of file '${output}'" level="ERROR" />
<log msg="${CLI.log}" level="ERROR" />
<fail message="Project Automator returned an error." />
</then>
</if>
</target>
<condition property="doVarSub">
<equals arg1="${config.deployer.doVarSub}" arg2="true" />
</condition>
<target name="bda.deployer.importVarSubs" depends="bda.deployer.createVarSubs" if="doVarSub" description="the entry point for the varsub implementation">
<log msg="Looking for varsub files with file suffix '.vs.xml' in directory '${varsubTmpDir}'" />
<foreach target="bda.deployer.importVarSubDeployer" param="varsubfile.path" inheritall="true" inheritrefs="true">
<fileset dir="${varsubTmpDir}" casesensitive="yes">
<include name="**/*.vs.xml" />
</fileset>
</foreach>
</target>
<target name="bda.deployer.importVarSubDeployer" depends="" if="doVarSub" description="the entry point for the varsub implementation">
<!-- check if the var sub file contains at least one deployment set, i.e. the varsub is not empty -->
<xmltask source="${varsubfile.path}">
<!-- count the child nodes of Root. We do not know if they are name DeploymentSet or DeploementSet -->
<copy path="count(/Root/child::node())" property="countDeploementSet" />
</xmltask>
<if>
<and>
<available file="${varsubfile.path}" type="file" />
<not>
<equals arg1="0" arg2="${countDeploementSet}" />
</not>
</and>
<then>
<property name="deployerReplicateInboundDir" location="${config.deployer.deployerInstallationPath}/../replicate/inbound" />
<log msg="At least one varsub was created, copy file '${varsubfile.path}' to Deployer replicate inbound dir at '${deployerReplicateInboundDir}'." />
<copy file="${varsubfile.path}" todir="${deployerReplicateInboundDir}" />
<basename property="varsubfile.file" file="${varsubfile.path}" />
<!-- the name of the vs.xml file is also the name of the map for which it should be imported -->
<propertyregex property="mapName" input="${varsubfile.file}" regexp="(.*)\.vs\.xml" select="\1" casesensitive="false" />
<log msg="-- Import Varsub parameters: -vsFile ${varsubfile.file}, -map ${mapName}, -project ${projectName}" />
<property name="output" value="${config.deployer.deployerInstallationPath}/logs/CLI.log" />
<exec executable="${config.deployer.deployerInstallationPath}/${deployerExecutable}" dir="${config.deployer.deployerInstallationPath}" output="${output}" resultproperty="importVarsubReturnCode" failonerror="false">
<arg value="--import" />
<arg value="-varsub" />
<arg line="-vsFile '${varsubfile.file}'" />
<arg line="-map ${mapName}" />
<arg line="-project ${projectName}" />
<arg line="-host ${config.deployer.deployerHost}" />
<arg line="-port ${config.deployer.deployerPort}" />
<arg line="-user ${config.deployer.deployerUsername}" />
<arg line="-pwd ${config.deployer.deployerPassword}" />
</exec>
<log msg="Importing the varsub file '${varsubfile.file}' restulted in return code ${importVarsubReturnCode}. See logs at '${output}'." />
<if>
<equals arg1="${importVarsubReturnCode}" arg2="8" />
<then>
<loadfile property="CLI.log" srcFile="${output}" />
<log msg="Deployer varsub import returned an error. Output of file '${output}'" level="ERROR" />
<log msg="${CLI.log}" level="ERROR" />
<fail message="Error when importing the varsub file ${varsubfile.file}." />
</then>
</if>
</then>
<else>
<log msg="-- no variable substitution will be used." />
</else>
</if>
</target>
<target name="bda.deployer.extractDeploymentCandidates">
<log msg="Extracting deployment candidates from project automator template '${projectAutomatorDefinition}'" />
<path id="path.projectdefinition">
<pathelement location="${projectAutomatorDefinition}" />
</path>
<pathconvert refid="path.projectdefinition" property="path.projectdefinition.file">
</pathconvert>
<log msg="Extracting deployment candidates from project automator template '${path.projectdefinition.file}'" />
<xmltask source="${path.projectdefinition.file}">
<call path="//DeploymentCandidate" target="bda.deployer.deployDeployer" buffer="candidates">
<param name="deploymentCandidate" path="@name" />
</call>
</xmltask>
</target>
<target name="bda.deployer.deployDeployer">
<log msg="-- Invoking Deployer executable '${config.deployer.deployerInstallationPath}/${deployerExecutable}' with parameters: -project ${projectName}, -dc myDeployment, -host ${config.deployer.deployerHost}, -port ${config.deployer.deployerPort}, -user ${config.deployer.deployerUsername}, -dc ${deploymentCandidate}" />
<property name="output" value="${config.deployer.deployerInstallationPath}/logs/CLI.log" />
<exec resultproperty="deployerResult" executable="${config.deployer.deployerInstallationPath}/${deployerExecutable}" dir="${config.deployer.deployerInstallationPath}" failonerror="false" output="${output}">
<arg value="--deploy" />
<arg line="-project ${projectName}" />
<arg line="-dc ${deploymentCandidate}" />
<arg line="-host ${config.deployer.deployerHost}" />
<arg line="-port ${config.deployer.deployerPort}" />
<arg line="-user ${config.deployer.deployerUsername}" />
<arg line="-pwd ${config.deployer.deployerPassword}" />
<arg value="-force" />
</exec>
<if>
<and>
<isset property="deployerResult" />
<equals arg1="${deployerResult}" arg2="8" />
</and>
<then>
<log msg="Deployer returned an error result code: '${deployerResult}'. Output of file '${output}':" level="ERROR" />
<loadfile property="CLI.log" srcFile="${output}" />
<log msg="${CLI.log}" level="ERROR" />
<fail message="Deployer returned an error result code: '${deployerResult}'." />
</then>
<else>
<log msg="Deployer succeeded with result code '${deployerResult}'." level="INFO" />
</else>
</if>
</target>
<target name="bda.deployer.createVarSubs" if="doVarSub">
<log msg="Creating variable substitution for target environment '${bda.targetEnv}'" />
<!-- store temp varsub files in a special vs tmp dir -->
<property name="varsubTmpDir" location="${config.tmpdir}/vs/${bda.targetEnv}/${fbrRepoName}" />
<antcall target="common.create_dir">
<param name="overwrite" value="false" />
<param name="dir" value="${varsubTmpDir}" />
</antcall>
<property name="groovyScript.CreateVarSub" location="resources/vs/CreateVarSub.groovy" />
<log msg="Calling '${groovyScript.CreateVarSub}' to create varsub file" />
<groovy src="${groovyScript.CreateVarSub}">
<arg line="-a '${projectAutomatorDefinition}'" />
<arg line="-p ${projectName}" />
<arg line="-t ${bda.targetEnv}" />
<arg line="-vs '${varsubDir}'" />
<arg line="-o '${varsubTmpDir}'" />
</groovy>
</target>
</project>