Lab 1
Participants configure a simple CI/CD pipelines for a sample SQL project
Overview:
- 1.1: Create a project from an existing database
- 1.2: Create a pipeline to publish the project to the database
- 1.3: Create a pipeline to build the project and run code analysis
- 1.4: Deploy our changes to the database
Workshop prerequisites
If your instructors have provided you with a connection string to the Wingtips database, you are ready to start the workshop. If you are doing this workshop as part of a self-paced learning experience, you will need to deploy the initial state of the Wingtips database yourself. The instructions for deploying the initial state of the Wingtips database are provided in LAB0.
You must have the following installed on your machine:
- Visual Studio Code
- the mssql and SQL Database Projects extensions for VS Code
- .NET SDK 8.0+
1.1 Create a project from an existing database
SQL Server Details
- Server: sqlbits.database.windows.net
- Admin: sqladmin
- Password: 2025PASSpr3con4U
- Database: Wingtips
Setup the project locally
- Connect to the Azure SQL Database in VS Code and open a new folder for this workshop. Name the folder
WingtipsWorkshopor something else memorable likeDevOpsWorkshopMarathon. - Using the SQL projects extension, select Create Project from Database in the upper right ellipsis menu.
- Follow the prompts to create a new SQL project named
Wingtipsfrom the database in a folder calledWingtipsin the workshop folder. -
From the SQL projects extension, right-click on the Wingtips project and select Build to build the project. This will create a
.dacpacfile in thebin/Debugfolder of the project. The.dacpacfile is a compiled version of the SQL database model. - Since we don’t want to include files like a
.dacpacin our future git repository, we need to add a.gitignorefile to the project. Open the Terminal in VS Code (View menu > Terminal or Ctrl+`), and run the following command to create a.gitignorefile in the workshop folder:
dotnet new gitignore
Push the project to a new private GitHub repository
- From the Source Control view in VS Code, initialize a git repository and commit the entire project to the repository with a commit message like “initial commit”.
- The commit button in the Source Control view will now display Publish Branch. Click the button to publish the branch to a new private GitHub repository.

- If you are prompted to sign in to GitHub, follow the prompts to sign in.
- Select the private option for the repository, adjusting the name if you want to.

- The repository will be created and the branch will be pushed to the new repository. A notification will appear in the bottom right corner of VS Code with a link to the new repository which will also be available in the GitHub website.

1.2 Create a pipeline to publish the project to the database
In this section we’re going to create a GitHub Actions pipeline to publish the SQL project to the database from templates provided by GitHub, all from the web browser. Later on in our workshop we’ll edit pipelines locally in VS Code.
- In the GitHub repository, select Actions.
- Search for the “.NET” template and select it to configure the pipeline, which starts with this template code:
# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
name: .NET
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
- Rename the pipeline file to
publish.yml. - Change the workflow to run only on manual trigger:
on:
workflow_dispatch:
Remove the push and pull_request events, which trigger the pipeline on every commit and pull request to the specified branches.
- Remove the
Teststep in the pipeline and modify the pipeline name in the YAML to “Deploy SQL project”. - Modify the
RestoreandBuildsteps to build the SQL project in theWingtipsfolder by specifying the project file:
- name: Restore dependencies
run: dotnet restore Wingtips/Wingtips.sqlproj
- name: Build
run: dotnet build Wingtips/Wingtips.sqlproj --no-restore
- Add a step to the pipeline that uses SqlPackage to publish the
.dacpacto the database after the SQL project has been built:
- name: Publish SQL project
run: |
sqlpackage /Action:Publish /SourceFile:Wingtips/bin/Debug/Wingtips.dacpac /TargetConnectionString:${{ secrets.SQL_CONNECTION_STRING }}
Note that the path to the source file is relative to the working directory of the pipeline, which starts at the root of the repository, and the name of the .dacpac file defaults to the name of the project.
- Commit the changes to the pipeline file.
- If you are using CodeSpaces ensure you do a
git pull
to get the latest change.
- Obtain the admin connection string for the Azure SQL Database or SQL Server instance. The connection string should look similar to:
Server=tcp:sqlbits.database.windows.net,1433;Initial Catalog=wingtips;Persist Security Info=False;User ID=<SQL ADMIN>;Password=<password>;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;
- YOUR DATABASE for
SQL_CONNECTION_STRINGbelow will be db-pass-test-XX where XX is your number - Add a secret to the GitHub repository named
SQL_CONNECTION_STRINGwith the connection string to the Azure SQL Database. Secrets are used to store sensitive information in GitHub Actions and are set in the repository settings under “secrets and variables” and “actions”.
Tip: Surround the Connection String in quotes in the secret
"<connection string>".
- We won’t run this pipeline just yet since we have no changes to apply to the database. We’ll run it later after we make some changes to the project.
Completed publish pipeline (expand to check your work)
# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
name: Deploy SQL project
on:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore Wingtips/Wingtips.sqlproj
- name: Build
run: dotnet build Wingtips/Wingtips.sqlproj --no-restore
- name: Publish SQL project
run: |
sqlpackage /Action:Publish /SourceFile:Wingtips/bin/Debug/Wingtips.dacpac /TargetConnectionString:${{ secrets.SQL_CONNECTION_STRING }}
1.3 Create a pipeline to build the project and run code analysis
In this section we’re going to leverage SQL code analysis to provide ongoing feedback on the quality of the SQL code in the project. The pipeline will run on every commit to the main branch. When we use the pipeline on pull requests, it will provide feedback on the quality of the code before it is merged into the main branch and acts as a CI (continuous integration) pipeline.
- To resolve a .NET issue - we need to create a
global.jsonfile in the ROOT of your directory. - Add this to the file:
{
"sdk": {
"version": "8.0.416",
"rollForward": "disable"
}
}
- Push your changes to Source Control.
- In VS Code, sync our project with the remote GitHub repository via
git pull. A folder.githubwill be created in the root of the project with aworkflowsfolder inside it. - In the
.github/workflowsfolder, create a new file namedbuild-codeanalysis.ymlwith the following content:
name: Build SQL project with code analysis
on:
push:
branches: [ "main" ]
paths:
- 'Wingtips/**'
pull_request:
branches: [ "main" ]
paths:
- 'Wingtips/**'
jobs:
build:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Build
run: dotnet build Wingtips/Wingtips.sqlproj /p:RunSqlCodeAnalysis=true
This pipeline will run on every commit to the main branch and pull requests against main.
- We’ll test our new pipeline with a new stored procedure. In VS Code, switch to a new branch named
new-venue. - In the
Wingtipsproject folder, add a new file indbo/StoredProceduresnamedNewVenue.sql. Add the following content to the file:
-- Creates a new Venue
CREATE PROCEDURE [dbo].[NewVenue]
@VenueId INT,
@VenueName NVARCHAR(128),
@VenueType NVARCHAR(30) = 'multipurpose',
@PostalCode NVARCHAR(20) = '98052',
@CountryCode CHAR(3) = 'USA'
AS
IF @VenueId IS NULL
BEGIN
RAISERROR ('Error. @VenueId must be specified', 11, 1)
RETURN 1
END
IF @VenueName IS NULL
BEGIN
RAISERROR ('Error. @VenueName must be specified', 11, 1)
RETURN 1
END
-- Insert Venue
INSERT INTO [dbo].Venues
([VenueId],[VenueName],[VenueType],[AdminEmail],[CountryCode], [PostalCode])
VALUES
(@VenueId, @VenueName,@VenueType,'admin@email.com',@CountryCode, @PostalCode)
RETURN 0
- Commit the new stored procedure to the
new-venuebranch and push the branch to GitHub. - In GitHub, create a pull request from the
new-venuebranch to themainbranch. - In the pull request, select the Checks tab and see that the pipeline is running.
- When the pipeline completes, select the Details link to see the results of the code analysis.
Code analysis results (expand to check your work)
The code analysis returns 1 warning:
Build succeeded.
/Users/Shared/CodeRepos/dzsquared/WingtipsWorkshop/Wingtips/dbo/StoredProcedures/NewVenue.sql(27,20,27,20): StaticCodeAnalysis warning SR0014: Microsoft.Rules.Data : Data loss might occur when casting from NVarChar(128) to NVarChar(50). [/Users/Shared/CodeRepos/dzsquared/WingtipsWorkshop/Wingtips/Wingtips.sqlproj]
1 Warning(s)
0 Error(s)
- Based on the code analysis results, we realize that our stored procedure
dbo.NewVenueis using the right size for the VenueName parameter (128 characters) but the table its being inserted into is using a smaller size. Let’s fix that by modifying the size of theVenueNamecolumn in thedbo.Venuestable to 128 characters. - In the
Wingtipsproject folder, open the filedbo.Tables/Venues.sqland change the size of theVenueNamecolumn from 50 to 128 characters:
CREATE TABLE [dbo].[Venues] (
[VenueId] INT NOT NULL,
[VenueName] NVARCHAR (50) NOT NULL,
...
- Commit the change to the
new-venuebranch and push the change to GitHub. - In GitHub, the pipeline will automatically run again and this time the code analysis will pass.
- In GitHub, merge the pull request to the
mainbranch.
1.4 Deploying our changes to the database
In this section we’re going to deploy the changes we made in the new-venue branch to the database using the publish pipeline we created earlier. Our last step from the previous section was to merge the changes into the main branch, so when we run the publish pipeline from the main branch, it will include the changes we made in the new-venue branch.
The changes we made added a new stored procedure and changed a column in a table. We don’t need to worry about how to deploy these changes to the database because the publish pipeline will automatically generate a script to deploy the changes when it uses SqlPackage to publish the project.
- In GitHub, select the Actions tab and select the Deploy SQL project pipeline.
- Click the Run workflow button to run the pipeline manually.
- Once the pipeline has completed, click on the Publish SQL project step to see the output of the SqlPackage command.
- Connect to the Azure SQL Database in VS Code or SSMS to verify that the stored procedure and table change have been deployed.
Next lab
Lab 2: Participants deploy SQL projects to different platforms