2

I'd like to find a way to obtain the current Git Branch that the project is running on. Essentially want to know whether I am currently in the Dev, UAT or Main branch.

Obviously, I can look down and see in the bottom corner:

enter image description here

But I want to utilise this and assign it to a variable so I can enable certain Config Settings depending on the correct Repository branch.

Currently, we are manually updating a Variable to assign which Config to use, so the Dev Config or UAT Config etc - but sometimes we forget to change this when creating the Nuget Packages.

Please note - this is for an Attended Bot that does not use UiPath Orchestrator, so it will not be utilising different Tenants.

If it's possible to get the Repository name as well that'd be even better as it's just to benefit my Exceptions created to have as much detail as possible - so having the environment would be great.

If anyone has been able to achieve this in the likes of Visual Studio or Visual Code, I might be able to Invoke similar code to make it work in UiPath Studio.

craig157
  • 355
  • 1
  • 3
  • 18
  • Interesting but I wonder about how you develop processes? In our company we have different folders for each process. So why not simply move each process to a subfolder? – kwoxer May 13 '21 at 15:50
  • @kwoxer - we use just the same project folder, but then have the multiple repository layers 'Dev, Uat & Prod'. Currently, we might use a variable in a Config file to declare which 'Environment' we are running in. For example, we might use a certain filepath for testing locally - then require a specific filepath for the Live environment. – craig157 May 14 '21 at 21:06
  • Now I understand. In that case the ReFramework can help you. https://docs.uipath.com/studio/docs/robotic-enterprise-framework In the Initialization you just define if it is DEV or PROD. You can do that with 2 different Excel file. But I would say have a look on that framework and how it can help you. Basically you define environment arguments in the Excel. – kwoxer May 15 '21 at 07:31
  • Hey @kwoxer - yes we already do it. I just wanted to see if it was possible to obtain the Branch Name via some method so that I could use this rather than defining the environment in an Excel Config. Cheers – craig157 May 15 '21 at 14:52
  • Somehow yes. But you wont find help from UiPath as they want you to use Orchestrator. So yeah maybe you need an alternative way. – kwoxer May 15 '21 at 19:22
  • To answer your question about printing the git repo name too: There is no such concept in git; a repository doesn't have a name. Instead you could get the parent folder name or a remote name. See [this answer](https://stackoverflow.com/questions/15715825/how-do-you-get-the-git-repositorys-name-in-some-git-repository) and adapt my answer below to run a different PowerShell command – etskinner Mar 28 '23 at 19:20

1 Answers1

1

You should use git from the command line to get the current branch name. According to this answer, a good way to do that would be:

git rev-parse --abbrev-ref HEAD

To implement this in UiPath Studio, you could use the Invoke PowerShell activity like so: Invoke PowerShell activity with git command

Properties panel of Invoke PowerShell command

And since it outputs a collection, use an Assign activity to get it as a string:

Using VB (default):

branch = outputCollection(0).ToString

Using C#:

branch = outputCollection[0].ToString()
etskinner
  • 160
  • 1
  • 7