连接到Visual Studio Online构建/测试任务中的外部服务 [英] Connect to external services inside Visual Studio Online build/test task

查看:119
本文介绍了连接到Visual Studio Online构建/测试任务中的外部服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在TFS Online上运行构建和测试过程.在我们尝试连接到外部服务之前,此方法可以正常工作.在我们的例子中是SQL数据库.
在这种情况下,关于我们应该嘲笑什么而不是什么的讨论并没有真正的帮助,因为目前我们需要这样做.

We are running our build and test process on TFS Online. This works fine, until we try to connect to an external service. In our case a SQL Database.
The discussion about what we should mock and not is not really helpful in this case, as currently we need to do this.

我们还尝试了一次简单的ping操作,但并没有成功:

We also tried just a simple ping, but not even that is getting out:

Test-Connection "172.217.18.100" #resolves to www.google.com

Testing connection to computer '172.217.18.100' failed: Error due to lack of resources

因此,我们的印象是大多数外部IP/端口/等.可以被锁定? 有办法打开它吗?如果是,怎么办?

So we have the impression that most outside IP's/Ports/etc. could be locked? Is there a way to open this up? If yes, how?

我无法想象我们是第一个尝试类似方法的人吗?从网站上下载东西,全部制作REST,等等?应该会以某种方式出现,不是吗?

I can't imagine that we are the first ones to try something like that? Downloading something from a website, making a REST all, etc? Should be possible somehow, no?

更新1:
我们对此问题有一个更详细的问题,

Update 1:
We had a bit a more detailed question about this issue here, but figured it was a more generic problem.

我们连接到Azure SQL时的错误消息是

The error message when we connect to Azure SQL is

System.Data.SqlClient.SqlException: 
A network-related or instance-specific error occurred while establishing a    connection to SQL Server. 
The server was not found or was not accessible. 
Verify that the instance name is correct and that SQL Server is configured to allow remote connections. 
(provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)`

但是命名管道提供者"部分具有误导性.如果您尝试连接到不存在的IP,也会在本地收到此消息.

But the Named Pipes Provider part is missleading. You also get this message locally if you try to connect to an IP that does not exist.

我们通过C#NUnit测试访问Azure SQL.

We access Azure SQL from our C# NUnit tests.

更新2:
我们从@ starain-MSFT尝试了这个想法,并安装了Azure SQL执行查询步骤/任务.安装工作正常,但似乎缺少组件.参见下图.

Update 2:
We tried out the idea from @starain-MSFT and installed the Azure SQL Execute Query step/task. Installation works fine, but it seems to miss a component. See picture below.

找不到具有以下功能的代理:azureps, sqlps,npm,node.js,msbuild,visualstudio,vstest

No agent could be found with the following capabilities: azureps, sqlps, npm, node.js, msbuild, visualstudio, vstest

基于已安装的应用列表,我认为它是azureps.

Based on installed apps list I assume it's azureps.

解决方案(部分):
好的,所以我们一路走错了路.问题不是防火墙(或与此有关的任何防火墙).问题是我们的app.config文件中没有正确的设置.
在单元测试中,我们对App.config文件的设置与对Web.config文件的设置相同.每个文件都有一个App.Debug.config和一个App.Release.config文件.虽然这对于Web应用程序来说效果很好,但是对于我们的单元测试显然不起作用.
我们仍在这里寻找一个好的解决方案. 我发现了此解决方案在Visual Studio中添加转换任务,但这并不是我们正在搜索的内容,因为我们不需要本地转换,而只需要在Visual Studio Teams中使用.

Solution (partly):
Ok, so we went down the wrong route all the way. The problem is not the firewall (or any firewalls for that matter). The problem was that our app.config file didn't had the right settings in it.
We had the same setup for our App.config files inside the unit tests as for our Web.config files. Each had a App.Debug.config and a App.Release.config file attached. While this worked fine for the web applications, this obviously didn't work for our unit tests.
We are still looking for a good solution here. I found this solution on how to add a transform task inside Visual Studio, but this is not exactly what we are searching, because we don't need the transform locally, but only in Visual Studio Teams.

app.config在Visual Studio Teams中转换
所以,我认为我们终于明白了.使用 ConfigTransform ,我们现在可以在构建过程中转换app.config文件.

app.config Transform inside Visual Studio Teams
So, I think we finally got it. With ConfigTransform, we can now transform our app.config files during the build process.

推荐答案

Windows托管的构建代理不会阻止1433出站.

Windows Hosted build agents don't block 1433 outbound.

  1. 如果要通过托管生成代理连接到SQL Azure,请确保已在SQL Azure防火墙设置中启用允许访问Azure服务".您不需要手动运行脚本.

SQL Azure防火墙设置

  1. 确保在单元测试期间使用正确的连接字符串.例如.在MSTest中,您需要将连接字符串添加到UnitTest项目的 App.config 中.

<connectionStrings>
  <add name ="TestContext" providerName="System.Data.SqlClient" 
  connectionString="Server=tcp:[ServerName].database.windows.net,1433;Initial Catalog=[DB Name];Persist Security Info=False;User ID=[User];Password=[Password];MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"/>
</connectionStrings>

就是这样.我刚刚使用EF,SQL Azure和amp;进行了快速测试. VSTS托管代理,它可以正常工作.

That's it. I just did a quick test with EF, SQL Azure & VSTS Hosted Agent and it worked.

这篇关于连接到Visual Studio Online构建/测试任务中的外部服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆