Markdown Viewer

GitLab CI Setup for SMT Studio Migration

This guide covers every prerequisite and configuration step required to run the generated smt-studio GitLab CI pipeline.


Overview

The pipeline:

  1. Runs on a node:18 Docker image
  2. Installs smt-studio globally
  3. Authenticates both Salesforce orgs using JWT (non-interactive, CI-safe)
  4. Runs smt-studio cli to perform the migration or CSV generation
  5. Uploads generated CSVs as GitLab job artifacts

Prerequisites

1. Salesforce External Client App (JWT Auth)

GitLab CI authenticates to Salesforce using JWT Bearer Flow. Salesforce recommends External Client Apps for new integrations.

Steps (repeat for each org):

  1. In Salesforce Setup, search for External Client Apps → New External Client App

    Legacy path: App Manager → New Connected App still works but is no longer recommended.

  2. Fill in the app name and contact email
  3. Under OAuth Settings, enable Enable OAuth
  4. Set Callback URL to https://login.salesforce.com/services/oauth2/callback (placeholder — not used by JWT flow)
  5. Enable Use Digital Signatures, upload your certificate (.crt file)
  6. Add OAuth scopes: Manage user data via APIs (api), Perform requests at any time (refresh_token, offline_access)
  7. Save and note the Consumer Key — this becomes SF_CLIENT_ID
  8. Click Manage → Edit Policies → set Permitted Users to Admin approved users are pre-authorized
  9. Assign the app to the migration user's Profile or Permission Set

If both orgs share the same certificate, one External Client App / SF_CLIENT_ID covers both.

2. Generate a Certificate and Private Key

openssl genrsa -out server.key 2048
openssl req -new -x509 -key server.key -out server.crt -days 3650 \
  -subj "/CN=smt-studio-ci"

3. Generate an SMT_SECRET

# macOS / Linux
openssl rand -hex 32

Store the output as the SMT_SECRET CI variable.


GitLab Project Setup

4. Add CI/CD Variables

Go to your project → Settings → CI/CD → Variables → Add variable and add:

Variable Value Protected Masked
SF_CLIENT_ID Consumer Key from the External Client App ✅ ✅
SF_JWT_KEY Full contents of server.key ✅ ✅
SMT_SECRET Random hex string from step 3 ✅ ✅

Enable Protected so the variables are only available on protected branches (e.g. main). Enable Masked so the values are redacted from job logs.

5. Commit the Load Plan to the Repository

The CI runner clones your repo but has no access to your local filesystem. The load plan must be committed.

Recommended structure:

your-repo/
  load-plans/
    load-plan-vehicle.json   ← committed here
  .gitlab-ci.yml
mkdir -p load-plans
cp ~/Documents/load-plan-vehicle.json load-plans/
git add load-plans/load-plan-vehicle.json
git commit -m "add load plan for Vehicle migration"
git push

6. Add the Pipeline File

Create .gitlab-ci.yml at the root of your repository with the generated content from SMT Studio's GitLab CI tab:

stages:
  - migrate

variables:
  SMT_SECRET: $SMT_SECRET

smt-migrate:
  stage: migrate
  image: node:18
  before_script:
    - npm install -g smt-studio
    - echo "$SF_JWT_KEY" > /tmp/server.key
    - sf org login jwt
        --client-id $SF_CLIENT_ID
        --jwt-key-file /tmp/server.key
        --username mchinnappan@salesforce.com.af102 --alias source-org
    - sf org login jwt
        --client-id $SF_CLIENT_ID
        --jwt-key-file /tmp/server.key
        --username mohan.chinnappan.n5.b3a2393cf971@agentforce.com --alias target-org
  script:
    # NOTE: load-plans/load-plan-vehicle.json must be committed to this repository under load-plans/
    - smt-studio cli
      - -s
      - mchinnappan@salesforce.com.af102
      - -t
      - mohan.chinnappan.n5.b3a2393cf971@agentforce.com
      - -l
      - load-plans/load-plan-vehicle.json
      - -o
      - migrate
      - --object
      - Vehicle__c
  artifacts:
    paths:
      - smt-output/*.csv
    expire_in: 30 days
  only:
    - main

Copy this directly from the 🦊 GitLab tab in SMT Studio's Migration screen — it is pre-filled with your connected orgs, load plan path, and selected objects.


Running the Pipeline

Trigger on push

Any push to main triggers the pipeline automatically (as configured in only: - main).

Trigger manually

  1. Go to your project → CI/CD → Pipelines → Run pipeline
  2. Select the branch → Run pipeline

Dry Run First (Recommended)

Before a full migration, change -o migrate to -o gen-csv-file:

  script:
    - smt-studio cli
      - ...
      - -o
      - gen-csv-file

The artifacts block will upload the generated CSVs for review:

  artifacts:
    paths:
      - smt-output/*.csv
    expire_in: 30 days

Download the CSVs from the pipeline job page and inspect them before promoting to migrate.


Troubleshooting

INVALID_LOGIN / JWT authentication fails

sf: command not found

ENOENT: load-plans/load-plan-vehicle.json

Variables not available in the job

Artifacts not appearing


Security Checklist