If you haven't already:
|
If you are using VSTS/TFS, then see Create VSTS/TFS build. |
Open the configuration page for your existing continuous integration server (eg, TeamCity, Jenkins, Bamboo, etc)
Add a build step to start LocalDB to use it for the shadow database:
"C:\Program Files\Microsoft SQL Server\130\Tools\Binn\SqlLocalDB.exe" |
create ReadyRollShadow -s |
Add a build step to use MSBuild to compile either the solution or the ReadyRoll project with these properties:
/p:GenerateSqlPackage=True /p:ShadowServer="(localdb)\ReadyRollShadow" /p:TargetServer="$(TargetServer)" /p:TargetUserName="$(TargetUserName)" /p:TargetPassword="$(TargetPassword)" /p:TargetDatabase="$(TargetDatabase)" |
The target database is only used for generating the build artifacts and it will not be modified.
If your CI server doesn't have a MSBuild task then you can execute MSBuild via a command line task:
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe" AdventureWorks.sln <properties from above...> |
If you have Visual Studio 2017 installed on your build agents, then instead use for example: |
TargetServer
, TargetUserName
, TargetPassword
, and TargetDatabase
for a database in one of your environments, for example test, staging, or production. This database is only used for generating the build artifacts and it will not be modified.By default, ReadyRoll creates the build artifacts in the bin\Release
or bin\Debug
subfolder (change the MSBuild property <OutputPath>
to use a different subfolder).
Configure the build so that any files written to that folder will be saved as build artifacts.
This will create the following build artifacts:
By default, during a build, the migrations and programmable objects in the project are validated using the Microsoft Transact-SQL parser.
If a shadow database is specified, then there is an additional validation step of running the migration scripts on that database.
Any validation errors will fail the build.
| Set this to True to produce the build artifacts without performing this validation. |
There are 6 different kinds of build artifacts that can be created:
A package deployment script can be deployed to any environment, either by:
ProjectName_DeployPackage.ps1
file. This PowerShell script can be used to execute the database deployment from a command prompt. Simply provide a value for the $DatabaseServer
variable (and optionally the $DatabaseUserName
and $DatabasePassword
if using SQL Server Authentication to connect to your database). A set of default SQLCMD variables will be provided to the SQL script, which can be overridden as needed. Also, it will save the build artifact ProjectName_Snapshot.nupkg.bin
into the dbo.__SchemaSnapshot
table to record the schema that was deployed and to enable reporting in the future.ProjectName_Package.sql
file and enable SQLCMD Mode (from the Query menu). Then, uncomment the SQLCMD Variables section at the beginning of the script, make any adjustment to the variables as appropriate to the target environment, and then deploy to the target server(s).
| Set this to True to generate the package deployment script and accompanying PowerShell script. |
| Set this to the version number to use in the package deployment script (e.g. 3.1.4.1337 ). If it is not specified, then, if set, the OctoPackPackageVersion property will be used, otherwise the AssemblyInfo.cs file will be used to determine the version number. |
| By default, the PowerShell script that ReadyRoll generates (used by VSTS/TFS, Octopus Deploy, and PowerShell command line deployment) includes validation to ensure that each of the required parameters is specified. Set this to True to skip variable validation during execution of the PowerShell script at deployment time. |
If you would like to use Octopus Deploy to deploy the database, then see Octopus Deploy.
| Overrides the default .nuspec filename for the OctoPack process, which, by default, is ProjectName.nuspec |
| Overrides the OctoPackTargetsPath , which, by default, is the version bundled with the ReadyRoll build components. |
ℹ️️ The preview/diff report is not available in ReadyRoll Core; it is only available in ReadyRoll Pro.
If a shadow database and a target database is specified, then a report containing the schema differences between the project state and the current version of the database is generated (as stored within your target database's [__SchemaSnapshot] table). This effectively gives you a preview of the changes that are to be made to the target database during deployment.
The patch deployment script is shown in the diff report, which includes a delta of migrations, programmable objects etc that have yet to be deployed to the database.
The diff report will only be produced if the target database was deployed using either the package deployment PowerShell script, the MSBuild CLI or the Octopus Deploy package . This is due to the fact that the schema snapshot is not inserted into the target database unless one of these methods is used. If the target database was deployed using SSMS, as an Embedded Resource or directly with SQLCMD.EXE, then the schema snapshot will not be available, therefore report generation will not be available. |
| Set this to True to skip generating a preview/diff report. |
ℹ️️ The drift report and drift correction script are not available in ReadyRoll Core; they are only available in ReadyRoll Pro.
If a target database is specified, then, by default, a drift report and a drift correction script are generated.
| Set this to True to skip generating a drift report and a drift correction script. |
| ℹ️️ Setting In the event that drift is detected within the target server/database and the build is successful, then the drift-correction script ( |
| Set this to By default, ReadyRoll will ignore any objects that exist in the target database that are not present in the database project. This is to accommodate the scenario where an environment contains objects that have been added as part of operational tasks rather than system-development tasks (e.g. a stored procedure used by a DBA to perform regular maintenance on the database), and are therefore considered to be outside the scope of source control. Setting this option to |
| Set this to By default, in the event that drift is detected (e.g. a column added directly in Production), and the resulting drift-correction operations would result in data-loss (i.e. the removal of the hypothetical column), ReadyRoll will cause the build to fail, thus preventing the drift-correction script from being copied to the |
Any of the |
A patch deployment script can only be run on the target database that it is generated from (or a database with an identical schema). It only contains the migration scripts (if any) & programmable objects (if any) that haven't already been run on that database.
If a target database is specified, then, by default, a patch deployment script is generated (called ProjectName.sql
).
| Set this to True to skip generating a patch deployment script. |
The shadow database is a temporary database where ReadyRoll can run your migration scripts. By running the migration scripts on a real database, SQL Server will check that they are valid SQL with no syntax errors, missing dependencies, etc.
As part of the shadow deployment process, a file containing a snapshot of your schema is produced and, upon deployment, will be inserted into the target database. During subsequent builds, the snapshot will be retrieved from the target database and used to generate the deployment preview and drift reports mentioned above. If at deployment time a snapshot file cannot be not found (i.e. because the shadow was not deployed at build time), a warning will be raised to indicate the impact to report generation. |
The shadow database can either be on LocalDB, a local instance of SQL Server Express, or any other version of SQL Server.
| SQL Server instance where the shadow database should be deployed. |
| By default, Windows Authentication is used. Set this to a username to use with SQL Server Authentication. |
| By default, Windows Authentication is used. Set this to a password to use with SQL Server Authentication. |
| Overrides the name of the shadow database, which, by default, is ProjectName_WindowsUserName_SHADOW |
The target database is a database in one of your environments, for example test, staging, or production. It will not be modified unless you specify DBReSyncOnBuild
and/or DBDeployOnBuild
.
| SQL Server instance where the target database is. |
| By default, Windows Authentication is used. Set this to a username to use with SQL Server Authentication. |
| By default, Windows Authentication is used. Set this to a password to use with SQL Server Authentication. |
| Overrides the name of the target database, which, by default, is ProjectName |
Whilst there are these options to change the target database automatically during a build, the ReadyRoll Release components should generally be used instead. |
| ℹ️️ Setting If set to |
| ℹ️️ Setting If set to |