Add to your pipeline — copy, paste, done

// Jenkinsfile pipeline { agent any environment { SCHEMA_PATH = 'db/schema.sql' DIALECT = 'postgres' FAIL_ON_BREAKING = 'true' SKIP_NO_SQL_CHANGE = 'true' } stages { stage('Schema Diff') { steps { sh 'curl -sL https://schemalens.tech/ci/jenkins-diff.sh | bash' } } } post { always { archiveArtifacts artifacts: 'schema_diff_report.md' } } }
Download Jenkinsfile Jenkinsfile Docs ⚡ Setup Wizard

📋 What the build console looks like

[Pipeline] stage
[Pipeline] { (Schema Diff)
[SchemaLens] Comparing schemas...

🔍 SchemaLens Schema Diff Report

🟢 Tables Added1
🔴 Tables Removed0
🟡 Tables Modified2
⚠️ Breaking Changes1
📊 Risk Score42/100 (Medium)
ALTER TABLE users
  ADD COLUMN email_verified_at TIMESTAMP;
[Pipeline] archiveArtifacts
[Pipeline] }

🏷️ Build description with risk score

Build #42 — Success
SchemaLens: Risk: Medium (42/100) | +1 -0 ~2 | 1 breaking

The build description is updated automatically so anyone browsing the build history can spot risky schema changes at a glance — no need to open the console log.

📦 Archived artifact

schema_diff_report.md 2.4 KB

Team members can download the full markdown report from the Build Artifacts section. The report includes:

  • Complete diff summary with table counts
  • Breaking change list with severity levels
  • Generated migration SQL (full script with Pro)
  • Risk score and recommendation

Why add schema diff to Jenkins?

🛡️ Prevent production incidents

Breaking changes like dropped columns, removed indexes, or altered constraints get flagged before merge — not after deploy.

📋 Console output reports

The full schema diff appears directly in the Jenkins build console. No external dashboards required — review drift where you already review logs.

🏷️ Build description summaries

Every build gets its description updated with risk score, table counts, and breaking change count. Spot risky builds in the build history instantly.

⏭️ Smart skip

Set SKIP_NO_SQL_CHANGE: 'true' and the stage skips entirely when no .sql files were modified — saving build time and agent resources.

⚡ Zero setup required

No database connections, no CLI installation, no license key. Just point the stage at two SQL files.

🚦 Fail the build on breaking changes

Set FAIL_ON_BREAKING: 'true' and the build fails if any dangerous schema changes are detected.

📊 Risk score at a glance

Each diff gets a 0-100 risk score. High-risk migrations get extra scrutiny in code review.

🔓 100% free for open source

The free tier includes breaking change detection, risk scoring, console reports, and artifact archiving. No credit card required.

How it works

1

Dump your schema

Export your database schema to a SQL file as part of your workflow (e.g., pg_dump --schema-only or commit your schema file to the repo).

2

Compare before and after

The stage compares the schema from your target branch against the schema in the current build. Any drift is surfaced instantly.

3

See the diff in console & build description

Enable POST_BUILD_COMMENT: 'true' and add a GITHUB_TOKEN or GITLAB_TOKEN credential. The stage posts a formatted summary to your PR or MR automatically.

Free vs Pro

FeatureFree TierPro (optional)
Schema diff summary
Breaking change detection
Risk score
Console output & build description
Archived artifacts
Smart skip (no SQL changes)
PR/MR comments (GitHub/GitLab)
Full migration SQL✅ Complete script✅ Complete script
Markdown export
JSON export
Rate limit15/min30/min

Full configuration reference

// Jenkins environment variables (Manage Jenkins → Credentials, or pipeline environment block) SL_LICENSE_KEY // optional — SchemaLens Pro license key for full migration output GITHUB_TOKEN // optional — GitHub PAT with repo scope for PR comments GITLAB_TOKEN // optional — GitLab token with api scope for MR comments // Pipeline environment variables SCHEMA_PATH 'db/schema.sql' // Path to current schema SQL file DIALECT 'postgres' // postgres | mysql | sqlite | mssql | oracle FAIL_ON_BREAKING 'false' // true = fail build on breaking changes SKIP_NO_SQL_CHANGE 'false' // true = skip stage when no .sql files changed POST_BUILD_COMMENT 'false' // true = post to PR/MR (needs SCM token) FORMAT 'markdown' // markdown | json | sql (sql needs Pro)

Example: PostgreSQL project with PR comments

// Jenkinsfile pipeline { agent any environment { SCHEMA_PATH = 'db/schema.sql' DIALECT = 'postgres' FAIL_ON_BREAKING = 'true' SKIP_NO_SQL_CHANGE = 'true' POST_BUILD_COMMENT = 'true' } stages { stage('Schema Diff') { steps { script { // Smart skip if (env.SKIP_NO_SQL_CHANGE == 'true') { def target = env.CHANGE_TARGET ?: 'main' def changed = sh( script: 'git diff --name-only origin/' + target + '..HEAD || true', returnStdout: true ).trim() if (!changed.contains('.sql')) { echo '[SchemaLens] No SQL changes — skipping.' currentBuild.description = 'Skipped — no SQL changes' return } } // Ensure tools sh 'which jq >/dev/null 2>&1 || (apt-get update -qq && apt-get install -y -qq jq curl) || true' // Fetch base schema sh '''git fetch origin "${CHANGE_TARGET:-main}" && git show "origin/${CHANGE_TARGET:-main}:$SCHEMA_PATH" > /tmp/schema_base.sql 2>/dev/null || echo "-- No base schema" > /tmp/schema_base.sql''' // Call SchemaLens API sh '''set -euo pipefail ENDPOINT="https://schemalens.tech/api/free-diff" [ -n "${SL_LICENSE_KEY:-}" ] && ENDPOINT="https://schemalens.tech/api/diff" BODY=$(jq -n --arg a "$(cat /tmp/schema_base.sql)" --arg b "$(cat "$SCHEMA_PATH")" --arg d "$DIALECT" --arg f "$FORMAT" '{schemaA:$a,schemaB:$b,dialect:$d,format:$f}') curl -sL -X POST "$ENDPOINT" -H "Content-Type: application/json" ${SL_LICENSE_KEY:+-H "X-License-Key: $SL_LICENSE_KEY"} -d "$BODY" > /tmp/response.json jq -r '.markdown // .migrationTeaser' /tmp/response.json > schema_diff_report.md ''' // Show report sh 'cat schema_diff_report.md' // Update build description def score = sh(script: 'jq -r ".riskScore.score // 0" /tmp/response.json', returnStdout: true).trim() def label = sh(script: 'jq -r ".riskScore.label // \"Unknown\"" /tmp/response.json', returnStdout: true).trim() def bc = sh(script: 'jq -r "(.summary.breakingChangeCount // (.breakingChanges | length) // 0)" /tmp/response.json', returnStdout: true).trim() currentBuild.description = "Risk: ${label} (${score}/100) | ${bc} breaking" // Fail on breaking if (env.FAIL_ON_BREAKING == 'true' && bc != '0') { error("[SchemaLens] ${bc} breaking change(s) detected.") } } } } } post { always { archiveArtifacts artifacts: 'schema_diff_report.md', allowEmptyArchive: true } } }

Start catching schema drift today

Free forever for open source. Upgrade to Pro for full migration generation.

Try SchemaLens Free View Pro Pricing

🏢 Need this for your team?

Preview the shared SchemaLens Team workspace: PR comment history, Slack drift alerts, migration safety scores, and a team risk dashboard — then start a 14-day free trial.

👁️ Preview Team Workspace Start Team Plan — $29/mo Calculate ROI

Generate manager approval email → · Book a setup call →