Search Results for ""

Migrating from GitLab

This document provides an overview of how to migrate from GitLab to CircleCI.

Tips provided by ImagineX Consulting

Source Control Setup

If you are using GitLab’s SCM, you will first need to migrate your source code to GitHub or BitBucket. See the following for details on how to import your code:

GitHub Enterprise

Following are the steps required for using the git command line tool to import your GitLab repo into GitHub Enterprise:

  1. Create an empty repository on your GitHub Enterprise instance.

  2. Create a bare clone of your GitLab.com repository on your local machine, fetching all remote tags (refs/tags/*) and copying all remote branch heads (refs/heads/\*) directly to their corresponding local branch heads:

    git clone git@gitlab.com:[owner]/[repo-name].git --bare
  3. Add your GitHub Enterprise repository as a remote reference in your local clone:

    cd [repo-name]
    git remote add enterprise git@[hostname]:[owner]/[repo-name].git
  4. Push all local references (refs/\*) up to your remote GitHub Enterprise repository:

    git push enterprise --mirror

If you need to export other GitLab artifacts, follow the GitLab documentation on exporting a project.

Once you have imported your code into GitHub or BitBucket, you can start creating a project in CircleCI using the Getting Started guide.

Build Configuration

If you are using GitLab’s CI/CD, you will need to migrate your build configuration. On GitLab, the build configuration is defined in a file called .gitlab-ci.yml in the root directory of your source code repository. If you use shell scripts to perform your build, you can reuse those scripts in CircleCI.

First, create a CircleCI build configuration file. In the root directory of your source code repository, create a folder named .circleci and create a file in that folder named config.yml. Next, follow the CircleCI documentation here to learn how to configure the .config.yml file.

The GitLab and CircleCI configurations will be different. It may be helpful to have both GitLab and CircleCI reference documentation open side-by-side to help with the conversion of the build steps:

Some differences that are worth calling out:

Defining a job that executes a single build step

GitLab CircleCI
job1:
  script: "execute-script-for-job1"
jobs:
  job1:
    steps:
      - checkout
      - run: "execute-script-for-job1"
GitLab
job1:
  script: "execute-script-for-job1"
CircleCI
jobs:
  job1:
    steps:
      - checkout
      - run: "execute-script-for-job1"

Specify a Docker image to use for a job

GitLab CircleCI
job1:
  image: node:10
jobs:
  job1:
    docker:
      - image: node:10
GitLab
job1:
  image: node:10
CircleCI
jobs:
  job1:
    docker:
      - image: node:10

Define a multi-stage build pipeline

Job1 and Job2 run concurrently. Once they’re done, Job3 runs. Once Job3 is done, Job4 runs.

GitLab CircleCI
job1:
  stage: build
  script: make build dependencies

job2:
  stage: build
  script: make build artifacts

job3:
  stage: test
  script: make test

job4:
  stage: deploy
  script: make deploy

stages:
  - build
  - test
  - deploy
version: 2
jobs:
  job1:
    steps:
      - checkout
      - run: make build dependencies
  job2:
    steps:
      - run: make build artifacts
  job3:
    steps:
      - run: make test
  job4:
    steps:
      - run: make deploy

workflows:
  version: 2
  jobs:
    - job1
    - job2
    - job3:
        requires:
          - job1
          - job2
    - job4:
        requires:
          - job3
GitLab
job1:
  stage: build
  script: make build dependencies

job2:
  stage: build
  script: make build artifacts

job3:
  stage: test
  script: make test

job4:
  stage: deploy
  script: make deploy

stages:
  - build
  - test
  - deploy
CircleCI
version: 2
jobs:
  job1:
    steps:
      - checkout
      - run: make build dependencies
  job2:
    steps:
      - run: make build artifacts
  job3:
    steps:
      - run: make test
  job4:
    steps:
      - run: make deploy

workflows:
  version: 2
  jobs:
    - job1
    - job2
    - job3:
        requires:
          - job1
          - job2
    - job4:
        requires:
          - job3

Execute jobs on multiple platforms

GitLab uses tags to identify build runners. CircleCI provides all major OSes and Docker and must explicitly set in config. See our Executors documentation for more information.

GitLab CircleCI
ubuntu job:
  tags:
    - ubuntu
  script:
    - echo "Hello, $USER!"

osx job:
  tags:
    - osx
  script:
    - echo "Hello, $USER!"
jobs:
  ubuntu-job:
    machine:
      image: ubuntu-1604:201903-01
    steps:
      - checkout
      - run: echo "Hello, $USER!"
  osx-job:
    macos:
      xcode: 11.3.0
    steps:
      - checkout
      - run: echo "Hello, $USER!"
GitLab
ubuntu job:
  tags:
    - ubuntu
  script:
    - echo "Hello, $USER!"

osx job:
  tags:
    - osx
  script:
    - echo "Hello, $USER!"
CircleCI
jobs:
  ubuntu-job:
    machine:
      image: ubuntu-1604:201903-01
    steps:
      - checkout
      - run: echo "Hello, $USER!"
  osx-job:
    macos:
      xcode: 11.3.0
    steps:
      - checkout
      - run: echo "Hello, $USER!"

Cache Dependencies

GitLab CircleCI
image: node:latest

# Cache modules in between jobs
cache:
  key: ${CI_COMMIT_REF_SLUG}
  paths:
    - node_modules/

before_script:
  - npm install

test_async:
  script:
    - node ./specs/start.js
jobs:
  test_async:
    steps:
      - restore_cache:
          key: source-v1-{{ checksum "package.json" }}
      - checkout
      - run: npm install
      - save_cache:
          key: source-v1-{{ checksum "package.json" }}
          paths:
            - node_modules
      - run: node ./specs/start.js
GitLab
image: node:latest

# Cache modules in between jobs
cache:
  key: ${CI_COMMIT_REF_SLUG}
  paths:
    - node_modules/

before_script:
  - npm install

test_async:
  script:
    - node ./specs/start.js
CircleCI
jobs:
  test_async:
    steps:
      - restore_cache:
          key: source-v1-{{ checksum "package.json" }}
      - checkout
      - run: npm install
      - save_cache:
          key: source-v1-{{ checksum "package.json" }}
          paths:
            - node_modules
      - run: node ./specs/start.js

For larger and more complex build files, we recommend moving over the build steps in phases until you get comfortable with the CircleCI platform. We recommend this order: