Automate, Accelerate, Accurate

Main menu

Post navigation

PowerShell and GitLab CI – Part 1

GitLab 8 adds built in CI as an option, making a single instance of GitLab not only for use as a version control system, but also a continuous integration solution. GitLab is available for both use over the internet, and also locally hosted. These posts will cover the use of the internet service.

The next few posts will detail how I set this up for use with PowerShell, tested it, and some of the gotchas I came across. Todays one will cover the pre-requisites I needed to setup, and initial configuration for a new project.

Git Client

Naturally, in order to perform our GIT operations we’ll need some type of client installed. Some options available are :

NB At the point of writing this articule Posh-Git is included in the Github Desktop client, which may give you the best of both worlds.

My choice of client at the moment is Git for Windows and using the Bash CLI. I’ve still to take a proper look at Posh-Git, but it’s in the pipeline….

SSH Keys

Using the Bash console, you can create a set of SSH keys, which are going to be used later. Starting a Bash session with Git for Windows can be done by right clicking within any Explorer window, and selecting Git Bash Here

Opening a Bash session

With the session open, type the following :

1

ssh-keygen-trsa

Creating the SSH keys

This creates a public and private key. If you accept the defaults, a folder called .ssh will be created in the root of your user profile. Within this, you will find two files, id_rsa.pub and id_rsa. The first of these will be used later when we are creating a test repository.

Register with GitLab

Browse to https://gitlab.com/users/sign_in

Follow the on-screen instructions to register

Open the .pub public key file created earlier, and copy it into the clipboard

Login to Gitlab

Click Profile Settings

Click SSH Keys.

Click ADD SSH KEY

Paste your public key into the Key box

In the Name box enter a descriptive name of your choice

Click ADD KEY.

Click Back to dashboard

Creating the Project

On this screen, we can import existing projects from other sources, such as GitHub, but for now, we’ll create a new one.

Click + NEW PROJECT

Enter HelloWorld into the Project path box

If you wish, enter text describing the project in the Description box

Click CREATE PROJECT

This will then take us to the project page of HelloWorld. If you further scroll down the page, commands for us to setup our repository locally are detailed.

Now startup a BASH session, and change to a directory where you want to create this sample repository. Use the commands provided in the above, from Create a new repository.

The first time that you perform the GIT CLONE command, you will be prompted if you trust the authenticity of the host, gitlab.com. Enter Yes. This information will then be recorded in a known_hosts file, which is placed within the .ssh folder referred to previously.

Once complete, close your BASH session.

With the project created, and the repository locally cloned, we’ll go into the projects settings and enable the CI options.

Click Settings

Click Services

Click Gitlab CI

Check Active

Click SAVE

When you do this, a green circle will appear next to GitLab CI on the right. New options will also appear on the left side, including Runners, CI Web Hooks, CI Settings, CI Services, and CI Events.

Click CI Services

Click Mail

The Mail option is used to send an email when a build process has completed. Mail is enabled by default, but only for builds that do not succeed. I find it handy to have this enabled for all builds. If you wish to do this.

Select the Notify check box

Click to clear the Notify check box.

Click SAVE.

That’s it for day 1. In the next article in this series we’ll deploy and configure a Windows Runner, and take a look at the options available.