UiPath-Services / UiPath-DevOps-Scripts

26 stars 23 forks source link

How to deploy to specific UIPATH folder #9

Closed taragurung closed 8 months ago

taragurung commented 8 months ago

Is it possible to deploy to a specific UIPATH folder in cloud.uipath.com, based on branching strategies in gitlab pipeline?

  1. We are using cloud uipath service
  2. Using the tools ok, works well but now the problem is we have 1 folder for DEV and Another for PROD. Now looking for a way so that when we merge to DEV branch it will deploy to DEV and then to PROD once merged to PROD branch.

Could not find the way to pass the folder name in deploy script. Is it even possible? Anyone tried and found a solution for this.

Jaeger-U commented 8 months ago

Hi @taragurung 👋🏼

I am not using this project, but the CLI directly for our CI/CD pipeline build in GitHub Actions. So what I am writing is only applicable to the direct usage of the CLI.

In the cli.exe, you can pass a flag --organizationUnit which will be the folder for which the process is deployed to.

Regarding your branches. What we have done is a single workflow which is initiated on pull request approval and that workflow can look at which branch is merged into the other and by that automatically determine if the process should be deployed to DEV or PROD.

I hope this helps 🙏🏼

Jaeger-U commented 8 months ago

However - when i look at the code, it seems there is an option to pass it to the deploy script in this project. Take a look here :)

SE-Abdullah commented 8 months ago

@taragurung yes, you can pass orchestrator folder name you want to deploy to in folder_organization_unit parameters. See some example here UiPathDeploy documentation

taragurung commented 8 months ago

This is how I am trying to select the folder but getting issues

"$env:CI_PROJECT_DIR\UiPathDeploy.ps1" "$env:CI_PROJECT_DIR\output_packages\" "http://cloud.uipath.com" "DefaultTenant" -UserKey XXXXXX -account_name XXXX -folder_organization_unit demo

Error: UiPath.Orchestrator.Client.Exceptions.OrganizationUnitInitializationException: Folder demo could not be found. Please make sure that this folder exists on Orchestrator, that your user has at least one role with the Folder View and SubFolder View permissions, and that the user has permissions to access the folder.

Few things I am confused about:

but not able to figure out the cuase for now, investigation and hit and trial in progress

SE-Abdullah commented 8 months ago

The exception says it could not find the orchestrator folder "demo". Double check if you have a parent folder named "demo". If demo is a sub-folder then you should pass "parentFolderName\demo"

taragurung commented 7 months ago

I have passed the full path with the subfolder as well ,something like this "Migrated Default\NonProduction\demo"

But only this pattern of deployment is working for me: . 'C:\scripts\UiPathDeploy.ps1' "C:\UiPath\Project\Package.1.0.6820.22047.nupkg" "https://uipath-orchestrator.myorg.com" default -UserKey axxxx2c93a717110a82 -account_name myAccount Once i use the one where i can pass folder_name its not working

SE-Abdullah commented 7 months ago

if this is the pattern you use please pass orchestrator folder folder_organization_unit see example below . 'C:\scripts\UiPathDeploy.ps1' "C:\UiPath\Project\Package.1.0.6820.22047.nupkg" "https://uipath-orchestrator.myorg.com" default -UserKey a7da29a2c93a717110a82 -account_name myAccount -folder_organization_unit "Migrated Default\NonProduction\demo"

if it does not work, please include the log details here and the script line of code (hide sensitive data)

taragurung commented 7 months ago

@SE-Abdullah-UiPath This is how I am running the deploy . "$env:CI_PROJECT_DIR\UiPathDeploy.ps1" "$env:CI_PROJECT_DIR\output_packages\" "https://cloud.uipath.com" "DefaultTenant" -orchestrator_user tara@XXX.com -orchestrator_pass mypasshere -folder_organization_unit "Migrated Default\NonProduction\demo"

Error logs: 2/6/2024 3:48:11 PM Unable to deploy project. Exit code 1 Failed to run the command. Could not connect to Orchestrator: https://cloud.uipath.com/ , Tenant: DefaultTenant, Username: Tara Gurung, Password: ***, OrganizationUnit: Migrated Default\NonProduction\demo, UseWindowsCredentials: False. Please make sure that the provided URL (https://cloud.uipath.com) is correct, available from your build agent, and not blocked by a firewall. If the Orchestrator is using a self-signed SSL certificate, make sure that the build agent trusts it. Ensure that all the steps at https://docs.uipath.com/orchestrator/docs/self-signed-certificates were correctly followed when creating the certificate. Stack trace: at UiPath.CommandLine.Clients.OrchestratorClientFactory.<>c__DisplayClass5_0.<<BuildClient>g__HandleBuild|8>d.MoveNext() --- End of stack trace from previous location --- at UiPath.CommandLine.Clients.OrchestratorClientFactory.BuildClient(BaseAuthenticatedOptions options, Boolean setOrganizationUnit) at UiPath.CommandLine.Services.Impl.DeployService.Run(DeployOptions options) at UiPath.CommandLine.Services.Impl.OptionsParser.<>c__DisplayClass7_0.<<WithTraceLogging>b__0>d.MoveNext() --- End of stack trace from previous location --- at UiPath.CommandLine.Services.Impl.OptionsParser.RunOptions(String[] args, Func3 notParsedFunc) System.InvalidOperationException: Microsoft.Rest.HttpOperationException: Operation returned an invalid status code 'BadRequest' at UiPath.Web.Client18_4.Account.AuthenticateWithHttpMessagesAsync(LoginModel loginModel, Dictionary2 customHeaders, CancellationToken cancellationToken) at UiPath.Orchestrator.Client.OrchestratorClientFactory.<>c__DisplayClass6_2.<<BuildAsync>b__2>d.MoveNext() --- End of stack trace from previous location --- at UiPath.Orchestrator.Client.Util.ExceptionsHandler.RunWithFriendlyExceptionMessages[T](Func1 func) {"message":"Invalid credentials, failed to login.","errorCode":1000,"traceId":"00-be7248152062350ef6bdc506b7b02532-4317833eef678728-00"} at UiPath.Orchestrator.Client.Util.ExceptionsHandler.RunWithFriendlyExceptionMessages[T](Func1 func) at UiPath.Orchestrator.Client.OrchestratorClientFactory.BuildAsync(String url, String tenantName, String username, String password, String organizationUnit, Boolean useWindowCredentials, IDictionary2 customHeaders, Int32 requestTimeout, Boolean setOrganizationUnit, TextWriter outWriter) at UiPath.CommandLine.Clients.OrchestratorClientFactory.<>c__DisplayClass5_0.<g__HandleBuild|8>d.MoveNext() Cleaning up project directory and file based variables 00:02 ERROR: Job failed: exit status 1`

SE-Abdullah commented 7 months ago

@taragurung it seems you are using uipath cloud orchestrator. The username and password only works with OnPrem orchestrator. See authentication options documentation here UiPathAuthenticationsOptions. For cloud orchestrator you can either use External App authentication (Recommended) or API Access. More on how to setup here UiPathAuthenticationsOptions. Check for sample codes on usage with External App Auth and API access here UiPathDeploy Documentation

Script sample of Deploy with External App authentication: . "$env:CI_PROJECT_DIR\UiPathDeploy.ps1" "$env:CI_PROJECT_DIR\output_packages\" "https://cloud.uipath.com" "DefaultTenant" -accountForApp myAccountForExternalApp -applicationId myExternalAppId -applicationSecret myExternalAppSecret -applicationScope "OR.Analytics OR.Assets OR.Audit OR.BackgroundTasks OR.Execution OR.Folders OR.Jobs OR.Machines OR.Monitoring OR.Queues OR.Robots.Read OR.Settings OR.Tasks OR.TestSetExecutions OR.Users.Read" -folder_organization_unit "Migrated Default\NonProduction\demo"

Script sample of Deploy with API access authentication: . "$env:CI_PROJECT_DIR\UiPathDeploy.ps1" "$env:CI_PROJECT_DIR\output_packages\" "https://cloud.uipath.com" "DefaultTenant" -UserKey a7da29a2c93a717110a82 -account_name myAccount -folder_organization_unit "Migrated Default\NonProduction\demo"

taragurung commented 7 months ago

Thanks for your continuous response @SE-Abdullah but I have tried the syntax , and its not helping, when i dont add -folder_organization_unit it works but with folder it does not

. "$env:CI_PROJECT_DIR\UiPathDeploy.ps1" "$env:CI_PROJECT_DIR\output_packages\" "https://cloud.uipath.com" "DefaultTenant" -UserKey a2c93a -account_name myAccount -folder_organization_unit "Migrated Default\NonProduction\demo"

SE-Abdullah commented 7 months ago

@taragurung please always share the log so we can understand the issue. it could be that the folder you are trying to deploy the package to is not configured to use Folder Packages and it is using Tenant package feed? https://docs.uipath.com/orchestrator/automation-cloud/latest/user-guide/folders#folder-packages

taragurung commented 7 months ago

Here is the logs i have, meanwhile looking into Folder packages setup Error logs $ . "$env:CI_PROJECT_DIR\UiPathDeploy.ps1" "$env:CI_PROJECT_DIR\output_packages\" "https://cloud.uipath.com" "DefaultTenant" -UserKey XXXXXXX -account_name XXXXX -folder_organization_unit "Migrated Default\NonProduction\demo" 2/7/2024 3:46:05 PM UiPath CLI does not exist in this folder. Attempting to download it... 2/7/2024 3:47:48 PM UiPath CLI is downloaded and extracted in folder C:\GitLab-Runner\builds\v.com\romania\apa-nova\applications\data-management\demo\uipathcli\\22.10.8438.32859 2/7/2024 3:47:48 PM ----------------------------------------------------------------------------- 2/7/2024 3:47:48 PM uipcli location : C:\GitLab-Runner\builds\vxxx.com\romania\apa-nova\applications\data-management\demo\uipathcli\22.10.8438.32859\tools\uipcli.exe 2/7/2024 3:47:48 PM Executing C:\GitLab-Runner\builds\vxxxx.com\romania\apa-nova\applications\data-management\demo\uipathcli\22.10.8438.32859\tools\uipcli.exe package deploy C:\GitLab-Runner\builds\vxxx.com\romania\apa-nova\applications\data-management\demo\output_packages\ https://cloud.uipath.com DefaultTenant --accountName xxxxx --token H7ci*************** --organizationUnit Migrated Default\NonProduction\demo 2/7/2024 3:47:48 PM ----------------------------------------------------------------------------- 2/7/2024 3:47:58 PM Unable to deploy project. Exit code 1 Failed to run the command. Could not connect to Cloud Orchestrator, Refresh Token: ***, Tenant: DefaultTenant, Account Name: apanodwtjgmc, OrganizationUnit: Migrated Default\NonProduction\demo. Please make sure that the provided URL (https://cloud.uipath.com) is correct, available from your build agent, and not blocked by a firewall. If the Orchestrator is using a self-signed SSL certificate, make sure that the build agent trusts it. Ensure that all the steps at https://docs.uipath.com/orchestrator/docs/self-signed-certificates were correctly followed when creating the certificate. Stack trace: at UiPath.CommandLine.Clients.OrchestratorClientFactory.<>c__DisplayClass5_0.<<BuildClient>g__HandleBuild|8>d.MoveNext() --- End of stack trace from previous location --- at UiPath.CommandLine.Clients.OrchestratorClientFactory.BuildClient(BaseAuthenticatedOptions options, Boolean setOrganizationUnit) at UiPath.CommandLine.Services.Impl.DeployService.Run(DeployOptions options) at UiPath.CommandLine.Services.Impl.OptionsParser.<>c__DisplayClass7_0.<<WithTraceLogging>b__0>d.MoveNext() --- End of stack trace from previous location --- at UiPath.CommandLine.Services.Impl.OptionsParser.RunOptions(String[] args, Func3 notParsedFunc) UiPath.Orchestrator.Client.Exceptions.OrganizationUnitInitializationException: Folder Migrated Default\NonProduction\demo could not be found. Please make sure that this folder exists on Orchestrator, that your user has at least one role with the Folder View and SubFolder View permissions, and that the user has permissions to access the folder. at UiPath.Orchestrator.Client.OrchestratorClient.GetFolder(UiPathWebApi api, String folderName) at UiPath.Orchestrator.Client.OrchestratorClient.SetOrganizationUnit(String organizationUnit, Int32 timeoutSeconds) at UiPath.Orchestrator.Client.OrchestratorClient.InitializeAsync(Int32 requestTimeout, String organizationUnit, String tenantName, IDictionary2 customHeaders, Boolean setOrganizationUnit, TextWriter outWriter) at UiPath.Orchestrator.Client.OrchestratorClientFactory.BuildAsync(String refreshToken, String tenantName, String accountName, String organizationUnit, CloudDeployments cloudDeployment, IDictionary2 customHeaders, Int32 requestTimeout, Boolean setOrganizationUnit, TextWriter outWriter) at UiPath.CommandLine.Clients.OrchestratorClientFactory.<>c__DisplayClass5_0.<g__HandleBuild|8>d.MoveNext() Cleaning up project directory and file based variables 00:03 ERROR: Job failed: exit status 1`