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:
- Runs on a
node:18Docker image - Installs
smt-studioglobally - Authenticates both Salesforce orgs using JWT (non-interactive, CI-safe)
- Runs
smt-studio clito perform the migration or CSV generation - 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):
- 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.
- Fill in the app name and contact email
- Under OAuth Settings, enable Enable OAuth
- Set Callback URL to
https://login.salesforce.com/services/oauth2/callback(placeholder — not used by JWT flow) - Enable Use Digital Signatures, upload your certificate (
.crtfile) - Add OAuth scopes:
Manage user data via APIs (api),Perform requests at any time (refresh_token, offline_access) - Save and note the Consumer Key — this becomes
SF_CLIENT_ID - Click Manage → Edit Policies → set Permitted Users to
Admin approved users are pre-authorized - 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_IDcovers 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"
- Upload
server.crtto the External Client App - Store the contents of
server.keyas a GitLab CI variable (SF_JWT_KEY) — never commit the key file
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
- Go to your project → CI/CD → Pipelines → Run pipeline
- 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
- Verify the External Client App has Use Digital Signatures enabled and the correct
.crtuploaded - Confirm the user is pre-authorized via Profile or Permission Set
- Check
SF_CLIENT_IDmatches the Consumer Key exactly — no trailing spaces
sf: command not found
- The
node:18image does not include Salesforce CLI by default - Add to
before_scriptbefore thesf org login jwtcalls:- npm install -g @salesforce/cli
ENOENT: load-plans/load-plan-vehicle.json
- The load plan is not committed to the repository — follow step 5 above
Variables not available in the job
- Check the variable is not restricted to a tag or a different protected branch
- Unprotect the variable temporarily to test on a feature branch, then re-protect
Artifacts not appearing
- The
smt-output/directory is only created when CSVs are generated — run with-o gen-csv-filefirst - Adjust the
artifacts.pathspattern if you set a custom--csv-output-folder
Security Checklist
-
server.keyis never committed — stored only as a GitLab CI variable -
SF_CLIENT_ID,SF_JWT_KEY,SMT_SECRETare all Protected and Masked - Pipeline only runs on the protected
mainbranch (only: - main) - Run
gen-csv-filebeforemigrateon first use in any new environment - Rotate
SMT_SECRETand the JWT key/certificate on a regular schedule