Clone a GitLab Project

Create a pipeline that clones a private git repository hosted on GitLab.

This tutorial will walk you through adding an SSH Key to your GitLab account and cloning a GitLab private repository in a Refactr pipeline.

This tutorial assumes you already have:

  • A GitLab account
  • Access to a GitLab private repository
  • A Refactr Platform account, project, and pipeline already created

Step 1: Add a public key to your GitLab account

Generate a suitable SSH key pair.

Log in to GitLab, click on the Account Menu at the top right, and then choose Settings.

Copy and paste the public key generated previously into GitLab:

Step 2: Add a new Credential to your Refactr project

In your Refactr project, click on the Credentials on left navigation. Click New Credential, and proceed to create a new credential of the type Built-in: SSH Private Key.

Copy and paste the private key generated previously into the SSH Private Key field.

Step 3: Create a Credential Variable in your pipeline

Next, navigate to your pipeline, and Open in Builder. Choose the Variables button at the top right and click the Add Variable button. Ensure Variable Type is Credential and Allowed Credential Type to Built-in: SSH Private Key. You can optionally select the new credential you created in the previous step as the value for this variable.

Step 4: Add additional variables

Back in GitLab, navigate to the repository you wish to clone, and copy the SSH URL.

Switch back the the Variables tab in your Refactr Pipeline, and add the additional variables as shown in the image below. Paste the SSH Url just copied from GitLab into the value for the Repository Url. Be sure to click Save when you are done!

Step 5: Add and configure a Git Step

Now lets add a Git Step Module into your pipeline by dragging it into the builder from the list of step modules on the left pane. Click on the new step in the builder and the step properties form will appear on the right. Update the fields as shown in the image below. Be sure to toggle each of them to Evaluation Mode first because we are using variables for values! When you are finished, click Save at the top of the step form.

Step 6: Save the pipeline

Next, click Save at the top left of the builder, and a Save Pipeline dialog will appear. Enter some revision notes, and then click Save and Exit.

Step 7: Run the Pipeline

Lastly, click Run at the top left of the pipeline and the Run dialog will appear. Update any variable values as needed, and then click the Run button at the bottom.

Step 8: Monitor Run Progress

After clicking Run, you are brought to the current run in progress. Here you can see the console output of the selected run. If the run was successful, you should see a green check mark on the Git step on the left side, and some positive console output as shown in the image below.