[英]How to specify connection details for SSDT unit tests when run in Azure Devops yaml build pipeline
I am using SSDT unit tests for my database project.我正在为我的数据库项目使用 SSDT 单元测试。 They run no problem from Visual Studio.
它们从 Visual Studio 运行没有问题。
I would like these tests to run when I run my build pipeline on Azure DevOps, but when it is unable to connect.我希望在 Azure DevOps 上运行构建管道时运行这些测试,但无法连接时。 I get the following error:
我收到以下错误:
System.Data.SqlClient.SqlException: System.Data.SqlClient.SqlException: 110003;Invalid user or password.
System.Data.SqlClient.SqlException: System.Data.SqlClient.SqlException: 110003;无效的用户或密码。
The yaml for my test is as follows:我测试的yaml如下:
- task: VSTest@2
inputs:
testSelector: 'testAssemblies'
testAssemblyVer2: |
**\*test*.dll
!**\*TestAdapter.dll
!**\obj\**
searchFolder: '$(System.DefaultWorkingDirectory)'
Is there anything in particular that needs to go in the app.config file to get this to work?有什么特别需要进入 app.config 文件才能使其工作的吗? Note: I'm using SQL authentication.
注意:我正在使用 SQL 身份验证。
If the SSDT unit tests connects to the database server on your local machine, the azure devops pipeline will fail, for the hosted agents cannot communicate with your local machine.如果 SSDT 单元测试连接到本地计算机上的数据库服务器,azure devops 管道将失败,因为托管代理无法与本地计算机通信。
In this case you should create a self-hosted agent on your local machine, and run your pipeline on the self-hosted agent by defining the pool as your local agent pool in yaml pipeline.在这种情况下,您应该在本地计算机上创建一个自托管代理,并通过将池定义为 yaml 管道中的本地代理池来在自托管代理上运行您的管道。
If you are using other cloud database server like azure sql server.如果您使用其他云数据库服务器,如 azure sql server。 You can check if the connectionString in App.config is correct, and provide the correct User ID and Password .
您可以检查 App.config 中的 connectionString 是否正确,并提供正确的User ID和Password 。 The connectionString in app.config file is like below example
app.config 文件中的 connectionString 如下例所示
If you want to avoid storing sensitive information in a connection string in app.config.如果您想避免在 app.config 中的连接字符串中存储敏感信息。 You can store the connectionString in a secret variable in your pipeline.
您可以将 connectionString 存储在管道中的秘密变量中。
And use tokens connectionString="#{sqlDbTestConnectionString}#"
in app.config in place of real connection strings.并在 app.config 中使用令牌
connectionString="#{sqlDbTestConnectionString}#"
代替真正的连接字符串。
Then add replace token task before VsTest task in your pipeline to replace the tokens #{sqlDbTestConnectionString}#
in app.config with the real connectionString defined in secret variable.然后在管道中的 VsTest 任务之前添加替换令牌任务,以将 app.config 中的令牌
#{sqlDbTestConnectionString}#
替换为秘密变量中定义的真实 connectionString。
You can check this blog for more information.您可以查看此博客以获取更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.