-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathsfdeploytool.bat
343 lines (330 loc) · 10.1 KB
/
sfdeploytool.bat
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
:: Copyright (c) 2019 - Present, Rahul Malhotra. All rights reserved.
:: Use of this source code is governed by a BSD 3-Clause License that can be found in the LICENSE.md file.
@echo off
echo.
echo Welcome to SFDX Deployment Tool for Windows..!!
:: Reading configuration
:readConfig
cls
echo ----------config----------
for /f "tokens=1,2 delims==" %%a in (config.txt) do (
echo %%a: %%b
if "%%a"=="sourceOrg" (
set sourceOrgAlias=%%b
) else if "%%a"=="destinationOrg" (
set destinationOrgAlias=%%b
) else if "%%a"=="package.xmlLocationToDeploy" (
set packageXmlLocation=%%b
) else if "%%a"=="folderLocationForFetchedZip" (
set zipFolderLocation=%%b
) else if "%%a"=="waitTimeInMinutes" (
set waitTime=%%b
) else if "%%a"=="testLevel" (
set testLevel=%%b
) else if "%%a"=="runTests" (
set runTests=%%b
) else if "%%a"=="folderLocationToUndeploy" (
set folderLocationToUndeploy=%%b
)
)
echo --------------------------
:: Checking for org alias in configuration
:checkOrgAlias
if "%sourceOrgAlias%"=="" (
goto :updateSourceOrgAlias
) else if "%destinationOrgAlias%"=="" (
goto :updateDestinationOrgAlias
) else (
goto :startMenu
)
:: Updating the source org alias
:updateSourceOrgAlias
echo.
set /P sourceOrgAlias="Enter alias for source org:- "
echo.
echo 1. Connect to Developer/Production
echo.
echo 2. Connect to Sandbox
echo.
set /P orgChoice="Enter your choice (1/2) or Press Enter to add a custom URL:- "
if "%orgChoice%"=="1" (
set orgChoice=
set orgUrl="https://login.salesforce.com"
) else if "%orgChoice%"=="2" (
set orgChoice=
set orgUrl="https://test.salesforce.com"
) else (
echo.
set /P orgUrl="Enter the instance/login url for your org:- "
)
echo.
echo Authorizing source org...
echo.
echo sf org login web --alias %sourceOrgAlias% --instance-url %orgUrl% --set-default
call sf org login web --alias %sourceOrgAlias% --instance-url %orgUrl% --set-default
if %errorlevel%==1 (
echo.
echo Unable to authorize source org. Please try again.
set sourceOrgAlias=
) else (
(for /f "tokens=1,2 delims==" %%a in (config.txt) do (
if "%%a"=="sourceOrg" (
echo %%a=%sourceOrgAlias%
) else (
echo %%a=%%b
)
))>result.txt
del config.txt
ren result.txt config.txt
echo.
echo Source org authorized successfully. Config file updated.
)
goto :checkOrgAlias
:: Updating the destination org alias
:updateDestinationOrgAlias
echo.
set /P destinationOrgAlias="Enter alias for destination org:- "
echo.
echo 1. Connect to Developer/Production
echo.
echo 2. Connect to Sandbox
echo.
set /P orgChoice="Enter your choice (1/2) or Press Enter to add a custom URL:- "
if "%orgChoice%"=="1" (
set orgChoice=
set orgUrl="https://login.salesforce.com"
) else if "%orgChoice%"=="2" (
set orgChoice=
set orgUrl="https://test.salesforce.com"
) else (
echo.
set /P orgUrl="Enter the instance/login url for your org:- "
)
echo.
echo Authorizing destination org...
echo.
echo sf org login web --alias %destinationOrgAlias% --instance-url %orgUrl% --set-default
call sf org login web --alias %destinationOrgAlias% --instance-url %orgUrl% --set-default
if %errorlevel%==1 (
echo.
echo Unable to authorize destination org. Please try again.
set destinationOrgAlias=
) else (
(for /f "tokens=1,2 delims==" %%a in (config.txt) do (
if "%%a"=="destinationOrg" (
echo %%a=%destinationOrgAlias%
) else (
echo %%a=%%b
)
))>result.txt
del config.txt
ren result.txt config.txt
echo.
echo Destination org authorized successfully. Config file updated.
)
goto :checkOrgAlias
:: Displaying Menu
:startMenu
echo.
echo Welcome to SFDX Deployment Tool for Windows..!!
echo.
echo 0. Reload configuration
echo.
echo 1. Fetch metadata from source org
echo.
echo 2. Extract fetched metadata
echo.
echo 3. Validate metadata in destination org
echo.
echo 4. Deploy metadata in destination org
echo.
echo 5. Validate extracted metadata in destination org
echo.
echo 6. Deploy extracted metadata in destination org
echo.
echo 7. Un-Deploy metadata in destination org
echo.
set /P choice="Enter your choice:- "
cls
if "%choice%"=="0" (
set choice=
goto :readConfig
) else if "%choice%"=="1" (
set choice=
goto :fetchMetadata
) else if "%choice%"=="2" (
set choice=
goto :extractFetchedMetadata
) else if "%choice%"=="3" (
set choice=
goto :validateMetadata
) else if "%choice%"=="4" (
set choice=
goto :deployMetadata
) else if "%choice%"=="5" (
set choice=
goto :validateExtractedMetadata
) else if "%choice%"=="6" (
set choice=
goto :deployExtractedMetadata
) else if "%choice%"=="7" (
set choice=
goto :unDeployMetadata
)
echo.
pause
exit
:: Fetching the metadata from source Org
:fetchMetadata
cls
echo.
echo Fetching the metadata from source org...
echo.
echo sf project retrieve start -t "%zipFolderLocation%" -o %sourceOrgAlias% -x "%packageXmlLocation%"
echo.
call sf project retrieve start -t "%zipFolderLocation%" -o %sourceOrgAlias% -x "%packageXmlLocation%"
if %errorlevel%==1 (
echo Unable to fetch metadata
)
echo.
pause
goto readConfig
:extractFetchedMetadata
cls
echo.
echo Extracting the metadata previously fetched from source org...
echo.
echo powershell Expand-Archive %zipFolderLocation%/unpackaged.zip -DestinationPath %zipFolderLocation% -Force
call powershell Expand-Archive %zipFolderLocation%/unpackaged.zip -DestinationPath %zipFolderLocation% -Force
echo.
if %errorlevel%==1 (
echo Unable to extract metadata
) else (
echo Metadata extracted successfully and is available in folder "%zipFolderLocation%/unpackaged"
)
echo.
pause
goto readConfig
:: Validating the metadata in destination org
:validateMetadata
cls
echo.
echo Validating metadata in destination org...
echo.
if "%testLevel%"=="RunSpecifiedTests" (
echo sf project deploy validate --metadata-dir "%zipFolderLocation%/unpackaged.zip" -o %destinationOrgAlias% -w %waitTime% -l RunSpecifiedTests -t %runTests%
echo.
call sf project deploy validate --metadata-dir "%zipFolderLocation%/unpackaged.zip" -o %destinationOrgAlias% -w %waitTime% -l RunSpecifiedTests -t %runTests%
) else (
echo sf project deploy validate --metadata-dir "%zipFolderLocation%/unpackaged.zip" -o %destinationOrgAlias% -w %waitTime% -l %testLevel%
echo.
call sf project deploy validate --metadata-dir "%zipFolderLocation%/unpackaged.zip" -o %destinationOrgAlias% -w %waitTime% -l %testLevel%
)
if %errorlevel%==1 (
echo.
echo Unable to validate metadata
) else (
cls
echo.
echo Metadata validated successfully in destination org
)
echo.
pause
goto readConfig
:: Deploying the metadata in destination org
:deployMetadata
cls
echo.
echo Deploying metadata in destination org...
echo.
if "%testLevel%"=="RunSpecifiedTests" (
echo sf project deploy start --metadata-dir "%zipFolderLocation%/unpackaged.zip" -o %destinationOrgAlias% -w %waitTime% -l RunSpecifiedTests -t %runTests%
echo.
call sf project deploy start --metadata-dir "%zipFolderLocation%/unpackaged.zip" -o %destinationOrgAlias% -w %waitTime% -l RunSpecifiedTests -t %runTests%
) else (
echo sf project deploy start --metadata-dir "%zipFolderLocation%/unpackaged.zip" -o %destinationOrgAlias% -w %waitTime% -l %testLevel%
echo.
call sf project deploy start --metadata-dir "%zipFolderLocation%/unpackaged.zip" -o %destinationOrgAlias% -w %waitTime% -l %testLevel%
)
if %errorlevel%==1 (
echo.
echo Unable to deploy metadata
) else (
cls
echo.
echo Metadata deployed successfully in destination org
)
echo.
pause
goto readConfig
:: Validating the extracted metadata in destination org
:validateExtractedMetadata
cls
echo.
echo Validating extracted metadata in destination org...
echo.
if "%testLevel%"=="RunSpecifiedTests" (
echo sf project deploy validate --metadata-dir "%zipFolderLocation%/unpackaged" -o %destinationOrgAlias% -w %waitTime% -l RunSpecifiedTests -t %runTests%
echo.
call sf project deploy validate --metadata-dir "%zipFolderLocation%/unpackaged" -o %destinationOrgAlias% -w %waitTime% -l RunSpecifiedTests -t %runTests%
) else (
echo sf project deploy validate --metadata-dir "%zipFolderLocation%/unpackaged" -o %destinationOrgAlias% -w %waitTime% -l %testLevel%
echo.
call sf project deploy validate --metadata-dir "%zipFolderLocation%/unpackaged" -o %destinationOrgAlias% -w %waitTime% -l %testLevel%
)
if %errorlevel%==1 (
echo.
echo Unable to validate metadata
) else (
cls
echo.
echo Metadata validated successfully in destination org
)
echo.
pause
goto readConfig
:: Deploying the extracted metadata in destination org
:deployExtractedMetadata
cls
echo.
echo Deploying extracted metadata in destination org...
echo.
if "%testLevel%"=="RunSpecifiedTests" (
echo sf project deploy start --metadata-dir "%zipFolderLocation%/unpackaged" -o %destinationOrgAlias% -w %waitTime% -l RunSpecifiedTests -t %runTests%
echo.
call sf project deploy start --metadata-dir "%zipFolderLocation%/unpackaged" -o %destinationOrgAlias% -w %waitTime% -l RunSpecifiedTests -t %runTests%
) else (
echo sf project deploy start --metadata-dir "%zipFolderLocation%/unpackaged" -o %destinationOrgAlias% -w %waitTime% -l %testLevel%
echo.
call sf project deploy start --metadata-dir "%zipFolderLocation%/unpackaged" -o %destinationOrgAlias% -w %waitTime% -l %testLevel%
)
if %errorlevel%==1 (
echo.
echo Unable to deploy metadata
) else (
cls
echo.
echo Metadata deployed successfully in destination org
)
echo.
pause
goto readConfig
:: Un-Deploying the metadata in destination org
:unDeployMetadata
cls
echo.
echo Removing metadata from destination org...
echo.
echo sf project deploy start --metadata-dir "%folderLocationToUndeploy%" -o %destinationOrgAlias% -w %waitTime%
echo.
call sf project deploy start --metadata-dir "%folderLocationToUndeploy%" -o %destinationOrgAlias% -w %waitTime%
if %errorlevel%==1 (
echo.
echo Unable to remove metadata
) else (
echo.
echo Metadata removed successfully from destination org
)
echo.
pause
goto readConfig