2026-09-11 · Q&A guide

Connect Jenkins to Microsoft SQL Server – Quick Guide

Learn how to link Jenkins with MSSQL and execute scripts directly from a build pipeline.

Prerequisites

• A running Microsoft SQL Server instance accessible from the Jenkins host. • Jenkins 2.x or newer with administrative access. • Basic knowledge of Jenkins job configuration and shell scripting.

Add the JDBC Driver to Jenkins

Place the Microsoft JDBC Driver (mssql-jdbc‑<version>.jar) into the Jenkins shared library or a dedicated folder. Then add it to the global classpath via the Jenkins UI: Manage Jenkins → Configure System → Global properties → Add a new global property for the driver path, or set the environment variable JENKINS_CLASSPATH.

Store SQL Credentials Securely

Use Jenkins Credentials Binding to keep the database username and password out of plain text. Create a Username‑Password credential and reference it in the job with the variable names DB_USER and DB_PASS.

Create a Freestyle Job to Run SQL

Add an "Execute shell" or "Execute Windows batch" build step. Use the sqlcmd utility or a JDBC call. Example using sqlcmd:

#!/bin/bash
DB_HOST="your_sql_server"
DB_PORT="1433"
DB_NAME="YourDB"
DB_USER="${DB_USER}"
DB_PASS="${DB_PASS}"

sqlcmd -S ${DB_HOST},${DB_PORT} -d ${DB_NAME} -U ${DB_USER} -P ${DB_PASS} -Q "UPDATE dbo.YourTable SET Column='Value' WHERE Id=1;"

Takeaway: Jenkins can manage SQL Server updates by combining JDBC drivers, secure credentials, and the sqlcmd tool in a simple build step.

People also ask

What connection string does sqlcmd use for MSSQL?

Use -S servername,port and -d database. Example: -S myserver,1433 -d MyDB.

Can I run the script from a Jenkins pipeline?

Yes, use the Pipeline step "bat" or "sh" and reference the credentials with the credentials() step.

Do I need a plugin for JDBC?

Optional. The Microsoft JDBC driver works without a plugin; however, the JDBC plugin simplifies connection handling if you prefer Java-based execution.

Inspired by a public discussion on Stack Overflow. This article is an original explanation for learners.

← All posts