简体   繁体   English

在TFS构建之后通过远程桌面连接自动化IISRESET

[英]Automating IISRESET via remote desktop connection after a TFS build

I want to automate a process, which is invoked after a successful build on TFS. 我想自动化一个进程,在TFS上成功构建之后调用该进程。 The process will RDP to a test server, then call a C# application on that server, and reset IIS on that server. 该过程将RDP发送到测试服务器,然后调用该服务器上的C#应用​​程序,并重置该服务器上的IIS。 Each step will return the result so whether or not to call next step is based on the previous step. 每个步骤都将返回结果,因此无论是否调用下一步都是基于上一步骤。

There are a few obstacles in implementing it. 实施它有一些障碍。 Below is what I want to know if it is possible, and how to code it. 以下是我想知道的可能性,以及如何编码。

1) Invoking the process via a build on TFS 1) 通过TFS构建调用该过程

There is an option in Build definition to invoke automated test. Build定义中有一个选项可以调用自动测试。 I assume that the process can be invoked by implementing it as a test. 我假设可以通过将其作为测试来调用该过程。

2) RDP to remote server 2) RDP到远程服务器

I found the links below, which might be a solution 我找到了下面的链接,这可能是一个解决方案

Process rdcProcess = new Process();
rdcProcess.StartInfo.FileName = Environment.ExpandEnvironmentVariables(@"%SystemRoot%\system32\cmdkey.exe");
rdcProcess.StartInfo.Arguments = "/generic:TERMSRV/192.168.0.217 /user:" + "username" +  " /pass:" + "password";
rdcProcess.Start();

rdcProcess.StartInfo.FileName = Environment.ExpandEnvironmentVariables(@"%SystemRoot%\system32\mstsc.exe");
rdcProcess.StartInfo.Arguments = "/v " + "192.168.0.217"; // ip or name of computer to connect
rdcProcess.Start();

Run mstsc.exe with specified username and password 使用指定的用户名和密码运行mstsc.exe

Automating remote desktop connection 自动化远程桌面连接

3) IISReset 3) IISReset

I think it should be simply invoke " IISRESET " after RDP, but the problem is that, HOW to captrue the result of running IISRESET. 我认为它应该只是在RDP之后调用“ IISRESET ”,但问题是,如何限制运行IISRESET的结果。

The tools that might be suitable are: 可能适合的工具是:

1) Powershell - I don't know much about Powershell but am willing to learn if required 1)Powershell - 我对Powershell了解不多,但如果需要我愿意学习

2) C# 2)C#

My question is that how to implement it, any code example, and idea would be very much appreciated. 我的问题是如何实现它,任何代码示例和想法将非常感激。

in most cases you do not need to run iisreset 在大多数情况下,您不需要运行iisreset

if you want to upgrade an asp.net application, try to put app_offline.htm in the application folder, it will stop an application and application files will be unlocked 如果你想升级一个asp.net应用程序,尝试将app_offline.htm放在应用程序文件夹中,它将停止一个应用程序,应用程序文件将被解锁

after upgrading an application, it will restart automatically, or you can "touch" web.config to force restart 升级应用程序后,它将自动重启,或者您可以“触摸”web.config强制重新启动

You might be better using the Lab Build to run the scripts as part of an environment ob the target computer. 您可能更好地使用Lab Build将脚本作为目标计算机环境的一部分运行。 It can run any powershell against that machine as well as deploy and execute applications.... 它可以针对该机器运行任何PowerShell以及部署和执行应用程序....

Question: HOW to capture the result of running IISRESET 问题:如何捕获运行IISRESET的结果

I believe the old fashioned way, Hope this is what you are looking for 我相信老式的方式,希望这就是你要找的东西

c:> IISRESET >> C:\\temp.log c:> IISRESET >> C:\\ temp.log

You can use the above either from CMD or powershell 您可以使用CMD或powershell中的上述内容

In the past I have used Psexec to run commands against a remote server and where ever we need to control flow on the result of that command, we simply piped the console out to a shared folder and checked for our success flag. 在过去,我使用Psexec对远程服务器运行命令,在那里我们需要控制该命令结果的流量,我们只需将控制台输出到共享文件夹并检查我们的成功标志。

I am not sure if TFS can run commands in this manner but we implemented it on hudson/jenkins. 我不确定TFS是否可以以这种方式运行命令,但我们在hudson / jenkins上实现了它。

This won't answer your question directly but it may offer a better way forward 这不会直接回答您的问题,但可能会提供更好的前进方法

An Example: psexec.exe \\remoteserver "iisreset > h:\\iisreset.log" 示例:psexec.exe \\ remoteserver“iisreset> h:\\ iisreset.log”

Then run a grep or similar against the iisreset.log with your success flag as a condition to run the next step. 然后使用您的成功标志对iisreset.log运行grep或类似操作,作为运行下一步的条件。

Check my answer here which is somewhat related: Answer 在这里检查我的答案有点相关: 答案

If the user which runs the TFSBuild Service on the build server have enough rights on the test server then you can use psexec or powershell to run your commands remotely. 如果在构建服务器上运行TFSBuild服务的用户在测试服务器上拥有足够的权限,那么您可以使用psexec或powershell远程运行命令。 Read the below links: 阅读以下链接:

PSEXEC PSEXEC

PowerShell Remote commands PowerShell远程命令

There is no inbuilt activity/process which can help you run scripts on remote machines in TFS build workflow. 没有内置的活动/流程可以帮助您在TFS构建工作流中的远程计算机上运行脚本。

Step 1 for you is to identify how you are going to run scripts on the remote machine, as mentioned above you can either use PSEXEC or Powershell (though running PowerShell on remote computers may be a little more complicated to set up). 第1步是确定如何在远程计算机上运行脚本,如上所述,您可以使用PSEXEC或Powershell(尽管在远程计算机上运行PowerShell可能会稍微复杂一些)。

Step2, write the actual scripts to do the work, stop services, install MSI etc. Step2,编写实际脚本来完成工作,停止服务,安装MSI等。

Step3, Edit your current build defintion - create a new custom activity or make use of InvokeProcess activity from within your build definition to invoke the script that you have created in Step 2. InvokeProcess Activity 步骤3,编辑当前的构建定义 - 创建新的自定义活动或在构建定义中使用InvokeProcess活动来调用您在步骤2中创建的脚本.InvokeProcess Activity

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM