How To Clone A GitLab Repository In UiPath Studio?

How to clone a GitLab repository in UiPath Studio?

The Cloning of a GitLab repository using an Access Token, the Cloning of a GitLab repository using an SSH key, How to check the details of a git commit, and Where are stored the GIT credentials which is provided in Studio is explained in detail.

UiPath only supports the following methods of authentication for Git:

  • User password
  • Tokens (create the Personal Access token, provide a Token Name, Expiration date, in the Selected scopes select api scope (or the one that suits you best))
  • SAML SSO - The Sign in with GitHub option is available only for repositories hosted on github.com and requires the UiPath GitHub App to be installed in the organization or account.

====

Clone a GitLab repository using an Access Token

  1. Log in to GitLab
  2. In the right-corner click on Edit profile

1.png

  1. In the Access Tokens create the token and save its value somewhere as it is needed to connect in the Studio Git Source for a clone or init

Image_2022-04-11_13-50-56.png


More details can be found at Personal Access Tokens .

  1. In order to clone the project in Studio, go to the GitLab project and press Clone with HTTPS -> Copy URL

1.png

  1. In Studio -> Team -> GIT -> Clone Repository and provide these details:

Repository URL (the copied URL from step 4)

Check out directory (an empty folder somewhere locally)

Check Use Credentials

Select Token

Provide User (user from step 2) and Token and then click Open

2.png

  1. In the end, the project will be cloned to the project and perform the required Git actions.

====

Clone a GitLab repository using an SSH key

If a SSH key is not associated with the profile, follow the Generate an SSH key pair from Generate An SSH Key Pair .

If an existing SSH key pair is not present, generate a new one in Command Prompt.

  1. Open a CMD terminal.
  2. Type ssh-keygen -t followed by the key type and an optional comment. This comment is included in the .pub file that’s created. You may want to use an email address for the comment.

For example, for ED25519:

  • ssh-keygen -t ed25519 -C ""

For 2048-bit RSA:

  • ssh-keygen -t rsa -b 2048 -C ""
  1. Press Enter. Output similar to the following is displayed:
  • Generating public/private ed25519 key pair.
  • Enter file in which to save the key (/home/user/.ssh/id_ed25519):
  1. Accept the suggested filename and directory, unless you are generating a deploy key or want to save in a specific directory where you store other keys. Dedicate the SSH key pair to a specific host.
  2. Specify a passphrase ,
  • Enter passphrase (empty for no passphrase):
  • Enter the same passphrase again:
  1. A confirmation is displayed, including information about where the files are stored.

Public and private keys are generated. Add the public SSH key to the GitLab account and keep the private key secure.

Example for generating a 2048-bit RSA key:

3.png

Example of adding the generated 2048-bit RSA key into the GitLab account - Add an SSH Key To The Gitlab Account

Open the C:\Users\mXXXXXXv\.ssh\id_rsa.pub in Notepad++ for example and copy its whole content

1.png

Then perform these changes:

  1. Sign in to the GitLab account
  2. On the top bar, in the top right corner, select the avatar
  3. Select Preferences
  4. On the left sidebar, select SSH Keys
  5. In the Key box, paste the contents of the public key. If the key is manually copied, ensure to copy the entire key, which starts with ssh-rsa, ssh-dss, ecdsa-sha2-nistp256, ecdsa-sha2-nistp384, ecdsa-sha2-nistp521, ssh-ed25519, sk-ecdsa-sha2-nistp256@openssh.com, or sk-ssh-ed25519@openssh.com, and may end with a comment
  6. In the Title box, type a description, like Work Laptop or Home Workstation
  7. Optional. In the Expires at the box, select an expiration date

2.jpg

Now verify in Git Bash if it is possible to connect with the generated SSH key Verify That You Can Connect .

Verify that the SSH key was added correctly, by performing below

  1. For GitLab.com, ensure connecting to the correct server, confirm the SSH host keys fingerprints
  2. Open a terminal and run this command, replacing gitlab.example.com with your GitLab instance URL,
  • ssh -T git@gitlab.example.com
  1. If this is the first time connection, verify the authenticity of the GitLab host. If a message like below is observed,

The authenticity of host 'gitlab.example.com (35.231.145.151)' can't be established.

ECDSA key fingerprint is SHA256:HbW3g8zUjNSksFbqTiUWPWg2Bq1x8xdGUrliXFzSnUw.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added 'gitlab.example.com' (ECDSA) to the list of known hosts.

  1. Type yes and press Enter
  2. Run the ssh -T git@gitlab.example.com command again. You should receive a Welcome to GitLab, @username! message. If the welcome message doesn’t appear, you can troubleshoot it by running ssh in verbose mode,
  • ssh -Tvvv git@gitlab.example.com

Example for testing the connection with the 2048-bit RSA generated key in Git Bash:

On running the ssh -T git@gitlab.example.com command again, a Welcome to GitLab, @username! message should be received.

1.jpg

Test the Clone with SSH in Git Bash,

First, go to the GitLab repository and copy the URL from Clone with SSH

2.jpg

Then in Git Bash after connecting using the SSH key, type git clone git@gitlab.com:r3478/RobotAutomation.git (in your case it will be a different value)

Example:

3.jpg

Now Clone Repository in UiPath Studio

4.png

Select Use SSH (provide the path for the generated private key path C:\Users\mXXXXXv\.ssh\id_rsa.pub and its passphrase if you created one (if not leave the field empty) in the Password box)

5.jpg

Then press Yes in order to acknowledge the warning.

6.png

If everything is good, the project is cloned locally.

7.png

Make a small modification, commit the change and push the commit to the GitLab repository.

8.png

9.png

Results:

10.png

Reference: Managing Projects Git Over SSH

====

How to check the details of a Git Commit?

  1. Open the Git Bash (or your preferred Git tool)
  2. Use ssh -T git@gitlab.com to connect via SSH key to GitLab and provide the Passphrase to set up one

Example:

8.jpg

  1. Use the cd and the local path for the Studio project that was linked before and have some committed actions to the repository

Example:
cd C:/Users/mXXXXXv/'OneDrive - UiPath'/Documents/UiPath/RobotAutomation3/

9.jpg

  1. Use git show then the format and the commit SHA id (only git show and commit SHA id are required)

Example:
git show --pretty=fuller 2109b6cb12142ecc89f94d9a67ad77cbc9322881

10.jpg


For example, the %cn, %h, %cd and %s characters in the following command are replaced with the committer name, abbreviated commit hash, committer date, and the subject, respectively.

Example:
git log --pretty=format:"%cn committed %h on %cd with note %s"

11.jpg

  1. To list all the files that were touched in a commit, use git show --pretty="" --name-only and the SHA commit id

Example:
git show --pretty="" --name-only 2109b6cb12142ecc89f94d9a67ad77cbc9322881

12.jpg

More details about the Git-Show command can be found at Git Show Atlassian .

The complete list of placeholders can be found in the Pretty Formats section of the git log manual page.
Note: In order to find a specific commit SHA id, go to the repository in GitLab -> click on commits

Example:image.png


Then from the list find on commit and click on Copy commit SHA (in our case we had 2109b6cb12142ecc89f94d9a67ad77cbc9322881)

13.jpg

====

Where are stored the GIT credentials which is provided in Studio?

After a successful login with your Git repository credentials, the GIT credentials will be stored automatically in Run -> Credential Manager -> Windows Credentials

image.png


Example:

4.jpg

1 Like