Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Referring to other files in SQL Pre-deployment script using Devops Self-Hosted agent

$
0
0

We are using DevOps YAML pipelines to build and deploy database changes to our production environment. The database is deployed through a DACPAC file. We have a pre and post deployment file configured in the database project. In the predeployment file we add explicit database schema changes which would otherwise trigger data loss errors when the DACPAC is deployed, such as dropping objects or renaming tables or columns. But because the DACPAC deployment evaluates the database schema without taking into account the predeployment scripts, we still get these data loss warnings if we don't explicitly execute the predeployment script first. For this I have added a SQL Script task before the DACPAC task in the deployment YAML file.The issue is that we prefer to use multiple predeployment scripts to separate certain tasks. Because a database project can only have 1 predeployment script, we use SQLCMD statements to call the other files from the main script. For some reason when I execute the pipeline it will correctly execute the predeployment script, but then starts searching for the other files in the wrong folder. I have referenced them with the standard :r .\<filename.sql> notation but this doesn't seem to work. Removing the .\ also doesn't help.Below is the content of the predeployment script:

PRINT N'Execute PreDeployKeysAndSystemUsers.sql':r .\PreDeployKeysAndSystemUsers.sqlPRINT N'Execute PreDeployUsersAndRoles.sql':r .\PreDeployUsersAndRoles.sqlPRINT N'Execute PreDeployDDLStatements.sql':r .\PreDeployDDLStatements.sql

And this is the YAML snippet that executes this script:

    - task: SqlAzureDacpacDeployment@1      displayName: 2. Execute PreDeployment Script      inputs:        azureSubscription: '${{ parameters.ServiceConnectionPrefix}}${{ parameters.env }}'        AuthenticationType: 'servicePrincipal'        ServerName: '$(ServerName)'        DatabaseName: '${{ parameters.SQLDatabaseName }}'        deployType: 'SqlTask'        SqlFile: '$(Pipeline.Workspace)/${{ parameters.SQLProjectName }}/${{ parameters.SQLProjectName }}/01_preDeployment/Script.PreDeployment_t10-asqldb-mdw.sql'

When this is executed we get the following error:

Deployment error

Note how the path of the predeployment script and the script with the name "PreDeployKeysAndSystemUsers.sql" is different despite the .\ reference in the script. It is probably important to note that we use a self-hosted agent to run the deployment from.

I'm at a loss how to configure this. Any help would be appreciated.


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>