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 -s https://schemalens.tech/ci/jenkins-diff.sh | bash' } } } post { always { archiveArtifacts artifacts: 'schema_diff_report.md' } } }
Download Jenkinsfile Jenkinsfile Docs

๐Ÿ“‹ 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 SQLFirst 5 linesโœ… 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 -s -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?

Get a personalized walkthrough of SchemaLens for your engineering team โ€” including SSO, shared workspaces, and Slack alerts.

Book a Demo Free Team Audit