Deployment Automation For SQL Server Integration Services
Deployment Automation For SQL Server Integration Services
SSIS was not originally designed with automated deployment in mind. However, any
database that uses SSIS projects and their packages needs a way of scripting the
deployment of them if the database is to be deployed rapidly, or via a build server.
Nat Sundar shows a technique that can be extended to manage the scripted
deployment of SSIS projects.
Overview:
In this article, Ill be demonstrating a method of automating the task of building and
deploying SSIS projects via a PowerShell script. By deployment, I mean the process
of setting up new software or making changes to existing software. The deployment
pipeline usually involves several phases, including installation, configuration,
running and testing.
SQL Server Integration Services only supports manual deployment using the SSDT
designer. The Integration services Deployment wizard is an add-on utility tool with
Visual Studio to deploy the packages to a target server. Although this tool can also
be executed from the command line, you need to have Visual Studio to use this
wizard tool, which limits this approach.
It may seem reasonable to deploy SSIS applications manually, and certainly this
may be true for simple applications that arent being actively developed. A team or
an individual is responsible for the deployment end to end, and so becomes the
subject matter expert on this topic over a period of time. However as the application
becomes more complex, the deployment process becomes more tedious to
maintain, and too intricate to become repeatable without introducing errors.
Deployment Automation:
Where you must deploy frequently and accurately, with reduced risk of human error
and less reliance on individual expertise, then SSSIS deployments should be
automated.
To support Agile methodology, we should be able to deploy a fresh build to the test
server after every sprint. It is relatively straightforward to deploy more frequently
with the help of deployment automation.
3) No manual mistakes
Once the deployment process has been defined correctly, then no manual
intervention is needed. This increases the availability of the test server. In addition,
the deployment can be done very frequently without impacting the development
productivity.
Once the deployment has been automated, the step-by-step details are available in
a system or script, normally kept in source control. This eliminates the need for a
subject matter expert to deploy the changes, as anyone in the team can support the
deployment by running the script.
Unfortunately Visual Studio doesnt support automation for SSIS deployment. Also
there are no tools available in the market to achieve this. To deploy SSIS
automatically, we need an alternative scripted approach to build and deploy the
SSIS packages. In this article, we will learn to build and deploy using a PowerShell
script.
This approach consists of three stages. In the first stage we will create a DLL to
support the build process. The DLL will be used in the second stage to build the SSIS
project using MSBuild.. Once the build has completed, this will create an ISPAC file
for each SSIS project. In the third stage we will deploy the ISPAC file to the target
server using PowerShell script.
Step 1: Creating a DLL to support Build:
Before automating the build, lets understand the mechanics behind the scene
during the build process. Lets understand the build process using the manual
deployment.
In Visual Studio / SSDT designer, the process of building a SSIS project creates the
ISPAC file in the bin\Development folder. The ISPAC file is a zip file which will contain
the following files.
Manifest file
In the proposed solution, we will be building the SSIS package using MSBuild. By
default, the MSBuild will not support building SSIS projects. We need to create a DLL
to extend the capability of MSBuild to build the SSIS projects. Lets first understand
the basics of MSBuild and then I will explain the step by step procedure to create an
assembly for MSBuild.
MSBuild overview:
MSBuild is a tool that is widely used in the industry to build windows applications. It
uses an XML schema in the project file that specifies the execution of the MSBuild
process.
Visual Studio hosts MSBuild to build managed projects. This is how the build and
deployment process within Visual Studio works seamlessly. As we are focusing on
XCopy deployment, we want to build the SSIS projects using the MSBuild directly.
Hence there is no need of Visual Studio on the build server.
Creating microsoft.sqlserver.integrationservices.Build.dll
You can download the source code by clicking the Download button on the page.
This has been highlighted in the picture below.
Once you have downloaded the source code from the above location you will need
to adjust the properties that must be based on your local settings. Unfortunately, as
it comes, the project will not compile, due to missing references and hardcoded
paths.
Lets extract the downloaded zip file into a folder and Open the
\main\ssismsBuild\Project\microsoft.sqlserver.integrationservices.Build.csproj file in
Visual studio. The screenshot below represents the project in Visual Studio. The
invalid references and the files will be highlighted in yellow warning as per the
image below.
This is because the sample project has been created with hard-coded references.
These references have to be updated as appropriate for installation on your
machine, but this is easy to do.
The second option is to use a text editor to open the project file and edit. I have
chosen the note pad editor to edit the project file.
When we install SQL Server 2012, the Development SDK for Visual Studio will be
installed in the Visual Studio shell. The system variable VS110COMNTOOLS
contains the location of the Visual Studio installation folder. This screenshot shows
the value of the system variable.
Once you have updated these, then save and close the project file. Now open the
project file using Visual Studio and you will now notice that there are no warnings in
the references section. As per the image below, now we have resolved all the invalid
references.
But still we do see the warning for the key file. The assembly needs to be signed
with a new file. So we can delete the existing key file.
Now, select the project properties on Visual Studio. The screenshot below shows the
project property for the SSIS project. Select the Signing tab to sign the assembly.
Now on the Choose a strong name key file drop-down box, select the New item.
This will list another dialog box to collect the name of the file and the password. In
following screenshot, Key file name has been specified as SSIS_KeyFile.
Once the assembly has been signed using this approach, the project is ready to
build. The solution can be built using the Build Solution from the Build menu.
After the completion of the build, you can expect to see the message Build
Succeeded in the status bar.
This dll should be copied to the folder C:\Program Files (x86)\Microsoft Visual Studio
10.0\Common7\IDE\PrivateAssemblies
Now we have created the DLL and this can be used to extend the capability of the
MSBuild. I recommend that you to check-in the source code into your source control
repository so that it can be used for future purposes.
Now we need to create an MSBuild project file. The MSBuild.exe will then make use
of this MSBuild project file. This project file will link the MSBuild and the
Integrationservices.dll to build and create an ISPAC file.
2 <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
3 DefaultTargets="SSISBuild">
1 </PropertyGroup>
1 <Message Text="Building SSIS project: $(SSISProjPath) using the
1 configuration: $(CONFIGURATION)........" />
2
<DeploymentFileCompilerTask
1
3 InputProject="$(SSISProjPath)"
1 Configuration="$(CONFIGURATION)"
4 ProtectionLevel="DontSaveSensitive">
1 </DeploymentFileCompilerTask>
5
</Target>
1
6 </Project>
1
7
The developer command prompt for Visual Studio sets the environment variables
that enable us to use .NET framework tools such MSBuild straight away. Hence I will
be using the Developer command prompt for this purpose.
Once opened, change the directory to the location of the SSIS project folder, as
show below in the image.
Now type the below mentioned script in the command prompt. This script will
invoke MSBuild and pass a few arguments.
This will successfully build the SSIS project. The resulting ISPAC file will be
generated after the successful build.
The ISPAC file can be seen in the bin\development folder.
Now we have completed the Build for a SSIS project and the ISPAC file is ready to
be deployed to the target server.
I will be using the PowerShell script to deploy the ISPAC file to the server. The ISPAC
file contains the SSIS project, Packages, Parameters and the manifest file. We must
pass two arguments to the deployment utility: the Target Server and the SSIS folder
name in the Catalog.
Well take deployment process step by step. I will use three PowerShell script
examples to help illustrate the whole process.
In the first example, we will be able to access the server using PowerShell script.
This script will help you to access the SSIS server from the PowerShell script.
The below mentioned PowerShell Script will help us to access the SQL Server
Integration service.
Pre-requisite:
I recommend that you should check whether these windows services are running on
the target server before executing the PowerShell script
With the help of PowerShell, we can access the methods and properties of SSIS
catalog. The namespace microsoft.sqlserver.management.integrationservices
contains the classes and interfaces that implement the functionality towards the
administration of the Integration services. To enable us to refer the methods inside
PowerShell script, we need to load the assembly first. This can be achieved by
executing this code.
2 [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Man
agement.IntegrationServices") | Out-Null;
This first script will help to test the connection with SQL Server Integration Services.
If you encounter any issues while executing this script, you should check whether
both services are running properly by accessing the server via SSMS.
3
# Load the IntegrationServices Assembly
4
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Ma
5 nagement.IntegrationServices") | Out-Null;
6
The below mentioned picture highlights the output of the script. The PowerShell
script will access SQL Server Integration Services and will print the details such as
the name of the catalog and server name .
Creating a folder in SSIS Catalog
As a next step, lets access the SSIS Catalog and create a folder so that we can
deploy the SSIS project to this folder.
Here is the script to access the SSIS catalog and to create a folder. I have declared
three variables in the script to store the connection details, Folder Name and the
Folder description.
5
6 # Load the IntegrationServices Assembly
7 [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Ma
nagement.IntegrationServices") | Out-Null;
8
# Create a connection object based on the connection string
9
# This connection will be used to connect to the Integration services service
1
0 $sqlConnection = New-Object System.Data.SqlClient.SqlConnection
$sqlConnectionString
1
1 # Let's create a new Integration Services object based on the SSIS name
space and
1
2 # the connection object created in the previous step
1 $integrationServices = New-Object
3 Microsoft.SqlServer.Management.IntegrationServices.IntegrationServices
$sqlConnection
1
4
1 echo $integrationServices.Catalogs["SSISDB"]
5
$catalog = $integrationServices.Catalogs["SSISDB"]
1
6 #As we have created an object for the catalog, we can access the catalog
2
1
2
2
2
3
2
4
2
5
We can now check that the new folder SSIS Deploy Demo has been created under
the SSIS catalog by opening SQL Server Management Studio and connecting to SQL
Server. Once connected, we expand the section Integration Services Catalogs ->
SSISDB to make sure that the project folder is there
Deploying SSIS Project:
Once the folder has been created, we can make use of the folder object to deploy
the project. This can be done by accessing the DeployProject function in the folder.
This function accepts two parameters, the Project Name and the Location of the
ISPAC file.
This script will connect to the server and create a folder. Finally the supplied ISPAC
file will be deployed to the target SSIS Catalog.
Script:
1 $ProjectFilePath =
"C:\WorkArea\Nat\SQL\Blog\SimpleTalk\Sample_SSIS_Project\Sample_SSIS_Proj
2 ect\bin\Development\Sample_SSIS_Project.ispac"
3 $ProjectName = "Sample_SSIS_Project"
4 $EnvironmentName = "CustomerA"
5
1
0 # Load the IntegrationServices Assembly
1 [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Ma
1 nagement.IntegrationServices") | Out-Null;
1 $integrationServices = New-Object
6 Microsoft.SqlServer.Management.IntegrationServices.IntegrationServices
$sqlConnection
1
7
1 echo $integrationServices.Catalogs["SSISDB"]
8
1 $catalog = $integrationServices.Catalogs["SSISDB"]
9
2
0 #As we have created an object for the catalog, we can access the catalog
2 $SSISfolder.Create()
4
Write-Host $FolderName "Folder has been created in the SSIS Catalog"
2
5
2
9
3
0
3
1
3
2
3
3
3
4
3
5
3
6
This PowerShell script will help us to deploy a single SSIS project with multiple
packages. However an ETL solution may contain numerous SSIS projects with many
more packages. PowerShell has various cmdlets to interact with folder and files, so
we can use the PowerShell script cmdlets to loop thru the available SSIS projects in
a folder. Now each SSIS project name can be passed to the PowerShell script to
deploy into the target server. Using this approach, we can deploy multiple SSIS
projects using a single PowerShell script.
You can extend this functionality further by maintaining various server connection
details in an XML file. This XML file can be read in the PowerShell script and the SSIS
project can be deployed to a suitable target server (Dev, Test, UAT, etc).
Summary:
The script weve described here will help you to build and deploy an SSIS project
using common tools that are available to a developer. This deployment can be done
through the command line, so this end-to-end process can easily be integrated with
any Continuous Integration tools. I recommend you to try out this approach on a
Sandbox machine in the development area. Once you have this working as youd
expect, you can then extend this to other servers.
Reference:
Deployment Automation:
https://www.red-gate.com/blog/database-lifecycle-management/5-big-benefits-
automated-deployment
https://www.simple-talk.com/sql/ssis/ssis-2012-projects-setup-project-creation-and-
deployment/
http://www.mattmasson.com/2012/06/publish-to-ssis-catalog-using-powershell/