Repository navigation
Expand file tree
/
Copy pathUiPathPack.ps1
More file actions
303 lines (257 loc) · 14.1 KB
/
Copy pathUiPathPack.ps1
File metadata and controls
303 lines (257 loc) · 14.1 KB
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
<#
.SYNOPSIS
Pack project into a NuGet package
.DESCRIPTION
This script is to pack a project into a NuGet package files (*.nupkg).
.PARAMETER project_path
Required. Path to a project.json file or a folder containing project.json files.
.PARAMETER destination_folder
Required. Destination folder.
.PARAMETER libraryOrchestratorUrl
(Optional, useful only for libraries) The Orchestrator URL.
.PARAMETER libraryOrchestratorTenant
(Optional, useful only for libraries) The Orchestrator tenant.
.PARAMETER libraryOrchestratorAccountForApp
(Optional, useful only for libraries) The Orchestrator CloudRPA account name. Must be used together with id, secret and scope(s) for external application.
.PARAMETER libraryOrchestratorApplicationId
(Optional, useful only for libraries) The external application id. Must be used together with account, secret and scope(s) for external application.
.PARAMETER libraryOrchestratorApplicationSecret
(Optional, useful only for libraries) The external application secret. Must be used together with account, id and scope(s) for external application.
.PARAMETER libraryOrchestratorApplicationScope
(Optional, useful only for libraries) The space-separated list of application scopes. Must be used together with account, id and secret for external application.
.PARAMETER libraryOrchestratorUsername
(Optional, useful only for libraries) The Orchestrator password used for authentication. Must be used together with the username.
.PARAMETER libraryOrchestratorPassword
(Optional, useful only for libraries) The Orchestrator username used for authentication. Must be used together with the password.
.PARAMETER libraryOrchestratorUserKey
(Optional, useful only for libraries) The Orchestrator OAuth2 refresh token used for authentication. Must be used together with the account name and client id.
.PARAMETER libraryOrchestratorAccountName
(Optional, useful only for libraries) The Orchestrator CloudRPA account name. Must be used together with the refresh token and client id.
.PARAMETER libraryOrchestratorFolder
(Optional, useful only for libraries) The Orchestrator folder (organization unit).
.PARAMETER version
Package version.
.PARAMETER autoVersion
Auto-generate package version.
.PARAMETER outputType
Force the output to a specific type. <Process|Library|Tests|Objects>
.PARAMETER language
The orchestrator language.
.PARAMETER disableTelemetry
Disable telemetry data.
.PARAMETER uipathCliFilePath
if not provided, the script will auto download the cli from uipath public feed. the script was testing on version 22.10.8432.18709. if provided, it is recommended to have cli version 22.10.8432.18709
.EXAMPLE
SYNTAX:
.\UiPathPack.ps1 <project_path> -destination_folder <destination_folder> [-version <version>] [-autoVersion] [--outputType <Process|Library|Tests|Objects>] [--libraryOrchestratorUrl <orchestrator_url> --libraryOrchestratorTenant <orchestrator_tenant>] [--libraryOrchestratorUsername <orchestrator_user> --libraryOrchestratorPassword <orchestrator_pass>] [--libraryOrchestratorUserKey <UserKey> --libraryOrchestratorAccountName <account_name>] [--libraryOrchestratorFolder <folder>] [-language <language>]
Examples:
package pack "C:\UiPath\Project\project.json" -destination_folder "C:\UiPath\Package"
package pack "C:\UiPath\Project\project.json" -destination_folder "C:\UiPath\Package" -version 1.0.6820.22047
package pack "C:\UiPath\Project\project.json" -destination_folder "C:\UiPath\Package" -autoVersion
package pack "C:\UiPath\Project" -destination_folder "C:\UiPath\Package"
package pack "C:\UiPath\Project\project.json" -destination_folder "C:\UiPath\Package" --outputType Tests -language en-US
.\UiPathPack.ps1 <project_path> -o <destination_folder> [-version <version>] [-autoVersion] [-outputType <Process|Library|Tests|Objects>] [-libraryOrchestratorUrl <orchestrator_url> -libraryOrchestratorTenant <orchestrator_tenant>] [-libraryOrchestratorUsername <orchestrator_user> -libraryOrchestratorPassword <orchestrator_pass>] [-libraryOrchestratorUserKey <auth_token> -libraryOrchestratorAccountName <account_name>] [-libraryOrchestratorAccountForApp <ExternaAppAccount> -libraryOrchestratorApplicationId <AppID> -libraryOrchestratorApplicationSecret <AppSecret> -libraryOrchestratorApplicationScope <AppScope>]
[-libraryOrchestratorFolder <folder>] [-language <language>]
Examples:
.\UiPathPack.ps1 "C:\UiPath\Project\project.json" --destination_folder "C:\UiPath\Package"
.\UiPathPack.ps1 "C:\UiPath\Project\project.json" -destination_folder "C:\UiPath\Package" -version 1.0.6820.22047
.\UiPathPack.ps1 "C:\UiPath\Project\project.json" -destination_folder "C:\UiPath\Package" -autoVersion
.\UiPathPack.ps1 "C:\UiPath\Project" -destination_folder "C:\UiPath\Package"
.\UiPathPack.ps1 "C:\UiPath\Project\project.json" -destination_folder "C:\UiPath\Package" -outputType Tests -language en-US
#>
Param (
#Required
[Parameter(Mandatory=$true, Position = 0)]
[string] $project_path = "", # Required. Path to a project.json file or a folder containing project.json files.
[string] $destination_folder = "", #Required. Destination folder.
[string] $libraryOrchestratorUrl = "", #Required. The URL of the Orchestrator instance.
[string] $libraryOrchestratorTenant = "", #(Optional, useful only for libraries) The Orchestrator tenant.
#Extranal Apps (OAuth) (Cloud/OnPrem)
[string] $libraryOrchestratorAccountForApp = "", #(Optional, useful only for libraries) The Orchestrator CloudRPA account name. Must be used together with id, secret and scope(s) for external application.
[string] $libraryOrchestratorApplicationId = "", #(Optional, useful only for libraries) The external application id. Must be used together with account, secret and scope(s) for external application.
[string] $libraryOrchestratorApplicationSecret = "", #(Optional, useful only for libraries) The external application secret. Must be used together with account, id and scope(s) for external application.
[string] $libraryOrchestratorApplicationScope = "", #(Optional, useful only for libraries) The space-separated list of application scopes. Must be used together with account, id and secret for external application.
#cloud API Access - Required
[string] $libraryOrchestratorAccountName = "", #(Optional, useful only for libraries) The Orchestrator URL.
[string] $libraryOrchestratorUserKey = "", #Required. The Orchestrator OAuth2 refresh token used for authentication. Must be used together with the account name and client id.
#On prem - Required
[string] $libraryOrchestratorUsername = "", #Required. The Orchestrator username used for authentication. Must be used together with the libraryOrchestratorPassword.
[string] $libraryOrchestratorPassword = "", #Required. The Orchestrator password used for authentication. Must be used together with the libraryOrchestratorUsername.
[string] $libraryOrchestratorFolder = "", #Optional, useful only for libraries) The Orchestrator folder (organization unit).
[string] $language = "", #The orchestrator language.
[string] $version = "", #Package version.
[switch] $autoVersion, #Auto-generate package version.
[string] $outputType = "", #Force the output to a specific type.
[string] $disableTelemetry = "", #Disable telemetry data.
[string] $uipathCliFilePath = "", #if not provided, the script will auto download the cli from uipath public feed. the script was testing on version 23.10.8753.32995.
[string] $SpecificCLIVersion = "", #CLI version to auto download if uipathCliFilePath not provided
[Parameter(ValueFromRemainingArguments = $true)]
$remainingArgs
)
#Log function
function WriteLog
{
Param ($message, [switch] $err)
$now = Get-Date -Format "G"
$line = "$now`t$message"
$line | Add-Content $debugLog -Encoding UTF8
if ($err)
{
Write-Host $line -ForegroundColor red
} else {
Write-Host $line
}
}
#Running Path
$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
#log file
$debugLog = "$scriptPath\orchestrator-package-pack.log"
#Validate provided cli folder (if any)
if($uipathCliFilePath -ne ""){
$uipathCLI = "$uipathCliFilePath"
if (-not(Test-Path -Path $uipathCLI -PathType Leaf)) {
WriteLog "UiPath cli file path provided does not exist in the provided path $uipathCliFilePath.`r`nDo not provide uipathCliFilePath paramter if you want the script to auto download the cli from UiPath Public feed"
exit 1
}
}else{
if($SpecificCLIVersion -ne ""){
$cliVersion = $SpecificCLIVersion;
}
else{
$cliVersion = "23.10.8753.32995"; #CLI Version (Script was tested on this latest version at the time)
}
#Verifying UiPath CLI installation
$uipathCLI = "$scriptPath\uipathcli\$cliVersion\tools\uipcli.exe"
if (-not(Test-Path -Path $uipathCLI -PathType Leaf)) {
WriteLog "UiPath CLI does not exist in this folder. Attempting to download it..."
try {
if (-not(Test-Path -Path "$scriptPath\uipathcli\$cliVersion" -PathType Leaf)){
New-Item -Path "$scriptPath\uipathcli\$cliVersion" -ItemType "directory" -Force | Out-Null
}
#Download UiPath CLI
#Invoke-WebRequest "https://www.myget.org/F/uipath-dev/api/v2/package/UiPath.CLI/$cliVersion" -OutFile "$scriptPath\\uipathcli\\$cliVersion\\cli.zip";
Invoke-WebRequest "https://uipath.pkgs.visualstudio.com/Public.Feeds/_apis/packaging/feeds/1c781268-d43d-45ab-9dfc-0151a1c740b7/nuget/packages/UiPath.CLI.Windows/versions/$cliVersion/content" -OutFile "$scriptPath\\uipathcli\\$cliVersion\\cli.zip";
Expand-Archive -LiteralPath "$scriptPath\\uipathcli\\$cliVersion\\cli.zip" -DestinationPath "$scriptPath\\uipathcli\\$cliVersion";
WriteLog "UiPath CLI is downloaded and extracted in folder $scriptPath\uipathcli\\$cliVersion"
if (-not(Test-Path -Path $uipathCLI -PathType Leaf)) {
WriteLog "Unable to locate uipath cli after it is downloaded."
exit 1
}
}
catch {
WriteLog ("Error Occured : " + $_.Exception.Message) -err $_.Exception
exit 1
}
}
}
WriteLog "-----------------------------------------------------------------------------"
WriteLog "uipcli location : $uipathCLI"
#END Verifying UiPath CLI installation
#Building uipath cli paramters
$ParamList = New-Object 'Collections.Generic.List[string]'
if($project_path -eq "" -or $destination_folder -eq "")
{
WriteLog "Fill the required paramters (project_path, destination_folder)"
exit 1
}
$ParamList.Add("package")
$ParamList.Add("pack")
$ParamList.Add("`"$project_path`"")
$ParamList.Add("--output")
$ParamList.Add("`"$destination_folder`"")
if($libraryOrchestratorUrl -ne ""){
$ParamList.Add("--libraryOrchestratorUrl")
$ParamList.Add($libraryOrchestratorUrl)
}
if($libraryOrchestratorTenant -ne ""){
$ParamList.Add("--libraryOrchestratorTenant")
$ParamList.Add($libraryOrchestratorTenant)
}
if($libraryOrchestratorAccountName -ne ""){
$ParamList.Add("--libraryOrchestratorAccountName")
$ParamList.Add($libraryOrchestratorAccountName)
}
if($libraryOrchestratorUserKey -ne ""){
$ParamList.Add("--libraryOrchestratorAuthToken")
$ParamList.Add($libraryOrchestratorUserKey)
}
if($libraryOrchestratorUsername -ne ""){
$ParamList.Add("--libraryOrchestratorUsername")
$ParamList.Add($libraryOrchestratorUsername)
}
if($libraryOrchestratorPassword -ne ""){
$ParamList.Add("--libraryOrchestratorPassword")
$ParamList.Add($libraryOrchestratorPassword)
}
if($libraryOrchestratorAccountForApp -ne ""){
$ParamList.Add("--libraryOrchestratorAccountForApp")
$ParamList.Add($libraryOrchestratorAccountForApp)
}
if($libraryOrchestratorApplicationId -ne ""){
$ParamList.Add("--libraryOrchestratorApplicationId")
$ParamList.Add($libraryOrchestratorApplicationId)
}
if($libraryOrchestratorApplicationSecret -ne ""){
$ParamList.Add("--libraryOrchestratorApplicationSecret")
$ParamList.Add($libraryOrchestratorApplicationSecret)
}
if($libraryOrchestratorApplicationScope -ne ""){
$ParamList.Add("--libraryOrchestratorApplicationScope")
$ParamList.Add("`"$libraryOrchestratorApplicationScope`"")
}
if($libraryOrchestratorFolder -ne ""){
$ParamList.Add("--libraryOrchestratorFolder")
$ParamList.Add("`"$libraryOrchestratorFolder`"")
}
if($language -ne ""){
$ParamList.Add("--language")
$ParamList.Add($language)
}
if($version -ne ""){
$ParamList.Add("--version")
$ParamList.Add($version)
}
if($PSBoundParameters.ContainsKey('autoVersion')) {
$ParamList.Add("--autoVersion")
}
if($outputType -ne ""){
$ParamList.Add("--outputType")
$ParamList.Add($outputType)
}
if($disableTelemetry -ne ""){
$ParamList.Add("--disableTelemetry")
$ParamList.Add($disableTelemetry)
}
#region Mask sensitive info before logging
$ParamMask = New-Object 'Collections.Generic.List[string]'
$ParamMask.AddRange($ParamList)
$secretIndex = $ParamMask.IndexOf("--libraryOrchestratorPassword");
if($secretIndex -ge 0){
$ParamMask[$secretIndex + 1] = ("*" * 15)
}
$secretIndex = $ParamMask.IndexOf("--libraryOrchestratorAuthToken");
if($secretIndex -ge 0){
$ParamMask[$secretIndex + 1] = $libraryOrchestratorUserKey.Substring(0, [Math]::Min(4, $libraryOrchestratorUserKey.Length)) + ("*" * 15)
}
$secretIndex = $ParamMask.IndexOf("--libraryOrchestratorApplicationId");
if($secretIndex -ge 0){
$ParamMask[$secretIndex + 1] = $libraryOrchestratorApplicationId.Substring(0, [Math]::Min($libraryOrchestratorApplicationId.Length, 4)) + ("*" * 15)
}
$secretIndex = $ParamMask.IndexOf("--libraryOrchestratorApplicationSecret");
if($secretIndex -ge 0){
$ParamMask[$secretIndex + 1] = ("*" * 15)
}
#endregion Mask sensitive info before logging
#log cli call with parameters
WriteLog "Executing $uipathCLI $ParamMask"
WriteLog "-----------------------------------------------------------------------------"
#call uipath cli
& "$uipathCLI" $ParamList.ToArray()
if($LASTEXITCODE -eq 0)
{
WriteLog "Done! Package(s) destination folder is : $destination_folder"
Exit 0
}else {
WriteLog "Unable to Pack project. Exit code $LASTEXITCODE"
Exit 1
}