Copado Setup for SMT Studio Migration
This guide covers every prerequisite and configuration step required to run the generated smt-studio Copado script as a Copado Function or Custom Job Step.
Overview
The script:
- Validates that required Copado Secure Parameters are injected (
SF_CLIENT_ID,SF_JWT_PRIVATE_KEY,SMT_SECRET) - Authenticates both Salesforce orgs using JWT (non-interactive)
- Runs
smt-studio clito perform the migration or CSV generation - Copies generated CSVs to the Copado artifact directory
Prerequisites
1. Salesforce External Client App (JWT Auth)
Copado 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 Copado Secure Parameter (SF_JWT_PRIVATE_KEY) — never commit the key file
3. Generate an SMT_SECRET
# macOS / Linux
openssl rand -hex 32
Store the output as the SMT_SECRET Copado Secure Parameter.
Copado Setup
4. Add Secure Parameters
In Copado, go to Secure Parameters (or your pipeline's environment configuration) and add:
| Parameter | Value | Notes |
|---|---|---|
SF_CLIENT_ID |
Consumer Key from the External Client App | Used for both org authentications |
SF_JWT_PRIVATE_KEY |
Full contents of server.key |
Multi-line value; include the -----BEGIN/END----- lines |
SMT_SECRET |
Random hex string from step 3 | Guards the smt-studio REST API |
SF_SOURCE_INSTANCE_URL |
e.g. https://login.salesforce.com |
Defaults to https://login.salesforce.com if not set |
SF_TARGET_INSTANCE_URL |
e.g. https://test.salesforce.com |
Defaults to https://test.salesforce.com if not set |
Copado injects these as environment variables into the Function runner at execution time — they are never written to disk or logged.
5. Commit the Load Plan to the Repository
The Copado 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
copado/
smt-migration.sh ← the generated script
mkdir -p load-plans copado
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 Migration Script
Create copado/smt-migration.sh with the generated content from SMT Studio's Copado CI tab:
#!/usr/bin/env bash
# Copado Function / Custom Job Step — SMT Studio migration
set -euo pipefail
# ── Injected by Copado Secure Parameters ──────────────────
: "${SF_CLIENT_ID:?}"
: "${SF_JWT_PRIVATE_KEY:?}"
: "${SMT_SECRET:?}"
# NOTE: load-plans/load-plan-vehicle.json must be committed to this repository under load-plans/
SMT_SOURCE="mchinnappan@salesforce.com.af102"
SMT_TARGET="mohan.chinnappan.n5.b3a2393cf971@agentforce.com"
SMT_PLAN="load-plans/load-plan-vehicle.json"
SMT_OPERATION="migrate"
SMT_OBJECT="Vehicle__c"
SMT_OUTPUT="./smt-output"
# ── Authenticate orgs via JWT ──────────────────────────────
echo "$SF_JWT_PRIVATE_KEY" > /tmp/server.key && chmod 600 /tmp/server.key
sf org login jwt \
--client-id "$SF_CLIENT_ID" \
--jwt-key-file /tmp/server.key \
--username "$SMT_SOURCE" --alias source-org \
--instance-url "${SF_SOURCE_INSTANCE_URL:-https://login.salesforce.com}"
sf org login jwt \
--client-id "$SF_CLIENT_ID" \
--jwt-key-file /tmp/server.key \
--username "$SMT_TARGET" --alias target-org \
--instance-url "${SF_TARGET_INSTANCE_URL:-https://test.salesforce.com}"
# ── Run smt-studio ─────────────────────────────────────────
smt-studio cli \
-s "$SMT_SOURCE" \
-t "$SMT_TARGET" \
-l "$SMT_PLAN" \
-o "$SMT_OPERATION" \
--object "$SMT_OBJECT" \
--csv-output-folder "$SMT_OUTPUT"
# ── Attach CSVs as Copado artifacts ───────────────────────
if [ -d "$SMT_OUTPUT" ]; then
cp -r "$SMT_OUTPUT"/*.csv "${COPADO_ARTIFACT_DIR:-./artifacts}/" 2>/dev/null || true
fi
Copy this directly from the 🚀 Copado tab in SMT Studio's Migration screen — it is pre-filled with your connected orgs, load plan path, and selected objects.
Make the script executable and commit it:
chmod +x copado/smt-migration.sh
git add copado/smt-migration.sh
git commit -m "add Copado migration script"
git push
7. Create a Copado Function
- In Copado, go to Functions → New Function
- Set Type to
Shell Script - Set Script Path to
copado/smt-migration.sh(relative to repo root) - Set Image to a Node.js image that includes
npm, e.g.node:18- If your Copado Function runner doesn't have
smt-studiopre-installed, add a setup step:npm install -g @salesforce/cli smt-studio
- If your Copado Function runner doesn't have
- Attach the Secure Parameters from step 4
- Save the Function
8. Add the Function to a Pipeline Step
- Open your Copado Pipeline → Edit
- Add a Custom Job step at the appropriate stage (e.g. after deployment validation)
- Select the Function created in step 7
- Set Run On to the target environment
- Save the pipeline
Running the Job
Manual trigger
- Open the Copado pipeline
- Click the custom job step → Run Now
- Monitor the log output in the Copado job console
Automated trigger
Configure the pipeline stage to run automatically after a preceding step (e.g. post-deployment validation) by setting the step's Execute condition.
Dry Run First (Recommended)
Before a full migration, change SMT_OPERATION in the script to gen-csv-file:
SMT_OPERATION="gen-csv-file"
The script will generate CSVs in SMT_OUTPUT and copy them to COPADO_ARTIFACT_DIR without loading any data to the target org. Review the artifacts before switching back to migrate.
Troubleshooting
SF_CLIENT_ID: unbound variable
- The Secure Parameter is not injected into the Function runner
- Verify the parameter name matches exactly (case-sensitive) and is attached to the Function or pipeline environment
INVALID_LOGIN / JWT authentication fails
- Confirm the External Client App has Use Digital Signatures enabled and the correct
.crtuploaded - Check the user is pre-authorized via Profile or Permission Set
- Verify
SF_SOURCE_INSTANCE_URL/SF_TARGET_INSTANCE_URLpoint to the correct Salesforce instance (production vs sandbox)
sf: command not found
- The runner image does not include Salesforce CLI — add
npm install -g @salesforce/clias a setup step before the script runs
smt-studio: command not found
- Add
npm install -g smt-studioas a setup step in the Function definition
ENOENT: load-plans/load-plan-vehicle.json
- The load plan is not committed to the repository — follow step 5 above
CSVs not appearing in artifacts
- The
smt-output/directory is only created whengen-csv-fileormigratecompletes successfully - Check
COPADO_ARTIFACT_DIRis set correctly in your Copado Function environment
Security Checklist
-
server.keyis never committed — stored only as a Copado Secure Parameter -
SF_CLIENT_ID,SF_JWT_PRIVATE_KEY,SMT_SECRETare all stored as encrypted Secure Parameters - The script uses
set -euo pipefail— any failure exits immediately, preventing partial migrations -
/tmp/server.keyis written withchmod 600— readable only by the current process - Run
gen-csv-filebeforemigrateon first use in any new environment - Rotate
SMT_SECRETand the JWT key/certificate on a regular schedule