Markdown Viewer

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:

  1. Validates that required Copado Secure Parameters are injected (SF_CLIENT_ID, SF_JWT_PRIVATE_KEY, SMT_SECRET)
  2. Authenticates both Salesforce orgs using JWT (non-interactive)
  3. Runs smt-studio cli to perform the migration or CSV generation
  4. 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):

  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 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

  1. In Copado, go to Functions → New Function
  2. Set Type to Shell Script
  3. Set Script Path to copado/smt-migration.sh (relative to repo root)
  4. Set Image to a Node.js image that includes npm, e.g. node:18
    • If your Copado Function runner doesn't have smt-studio pre-installed, add a setup step:
      npm install -g @salesforce/cli smt-studio
      
  5. Attach the Secure Parameters from step 4
  6. Save the Function

8. Add the Function to a Pipeline Step

  1. Open your Copado Pipeline → Edit
  2. Add a Custom Job step at the appropriate stage (e.g. after deployment validation)
  3. Select the Function created in step 7
  4. Set Run On to the target environment
  5. Save the pipeline

Running the Job

Manual trigger

  1. Open the Copado pipeline
  2. Click the custom job step → Run Now
  3. 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

INVALID_LOGIN / JWT authentication fails

sf: command not found

smt-studio: command not found

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

CSVs not appearing in artifacts


Security Checklist