2016-08-11 56 views
1

在我们的构建服务器上,我们有一个正在运行的进程,尤其是运行集成测试所需的运行进程,以访问数据库。TFS构建vNext - 成功构建后启动过程

这段软件可以在我们的存储库中进行更改,因此我创建了一个构建变更的CI构建。然后我想要做的是在成功构建之后用新的编译版本重新启动该过程,但是这部分我似乎无法工作。

我没有问题杀死正在运行的进程,并将结果部署到构建服务器上的特定位置,但似乎无论我尝试什么,只要正在运行的构建结束,我产生的进程就会被终止。

我曾尝试以下:

使用PowerShell

Start-Process <path to file> 

随着CMD

与 '加利福尼亚' 作为工具和以下参数:

<path to file> 
start <path to file> 
/c start <path to file> 
cmd <path to file> 
cmd start <path to file> 
cmd /c start <path to file> 

我也试着简单地提供.exe路径作为工具名称,没有参数,也没有运气。

它的工作效果如何?

那么,对于大多数上述方法,额外的步骤与PS命令Get-Process <exe name>*我得到了进程正在运行的结果。在停止该过程的步骤之后,同一步骤没有产生任何结果,因此可以启动新的更新过程。所以我认为它是有效的,vNext构建只是在构建结束后全部杀死它。

其他解决方案

我有2个解决方案留下了我能想到的应该工作,但是这两种解决方案都是我喜欢太复杂了,在我介绍相当复杂的构建过程,然后可能会出错,但这里有:

  1. 将生成服务器设置为部署的有效目标。然后我猜测我可以使用“目标机器上的PowerShell”步骤,即使我自己瞄准了它。我会假设它会作为独立的进程。这需要各种配置才能完成,并且需要为该任务编写远程PowerShell脚本。
  2. 编写一个可调用的小窗口服务,例如, REST,然后可以启动该进程,以便新的Windows服务成为拥有的线程。 - 这只是引入了一个新层,也可能需要更新。这也许可以手动更新而不是自动更新。

同样,我宁愿不使用2种解决方案中的任何一种,如果存在更好的解决方案。 :)

回答

2

在我结束了通过安装AutoIt固定的那一刻,并添加这个简单的脚本的“部署”文件夹:

While 1 ; Opens up a WHILE loop, with 1 as a constant, so it is infinite 
If Not ProcessExists("DelphiDebug.exe") Then Run("DelphiDebug.exe") ; if the process of DelphiDebug.exe doesn't exist, it starts it 
Sleep (10) ; Puts the script to sleep for 10 milliseconds so it doesn't chew CPU power 
WEnd ; Closes the loop, tells it to go back to the beginning 

Credit goes to this forum entry其中一个记事本例子制成

我已经然后作出重命名当前的版本,拷贝新建版本“部署”文件夹中的PowerShell脚本,停止正在运行的实例,并删除重命名的版本:

# CONSTANTS AND CALCULATED VARIABLES 
[string]$deploymentFolder = 'C:\Deployment-folder-on-local-machine' 
[string]$deploymentPath = "$deploymentFolder\my-program.exe" 
[string]$searchPathExistingVersion = $deploymentPath + '*' # The star is important so Get-Item does not throw an error 
[string]$toDeleteExeName = 'please-delete.exe' 
[string]$newCompiledVersionFullPath = "$env:BUILD_SOURCESDIRECTORY\sub-path-to-bin-folder\my-program.exe" 
[string]$processName = 'my-program' 
[string]$searchPathToDeleteVersion = "$deploymentFolder\$toDeleteExeName*" # The star is important so Get-Item does not throw an error 

# EXECUTION 
Write-Verbose "Search path: $searchPathExistingVersion" 
$existingVersion = Get-Item $searchPathExistingVersion; 
if ($existingVersion) { 
    Write-Debug "Match found: $existingVersion" 
    Rename-Item $existingVersion.FullName $toDeleteExeName 
} else { 
    Write-Debug 'No existing file found' 
} 
Write-Verbose "Copy new version from path: $newCompiledVersionFullPath" 
Copy-Item $newCompiledVersionFullPath $deploymentPath 
Write-Verbose 'Stopping running processes' 
Get-Process ($processName + '*') | Stop-Process # The new version is auto started with a running AutoIt script in the deployment folder. 
Write-Verbose "Deleting old versions with search path: $searchPathToDeleteVersion" 
$toDeleteVersion = Get-Item $searchPathToDeleteVersion 
if ($toDeleteVersion) { 
    Write-Debug "Match found: $toDeleteVersion" 
    Remove-Item $toDeleteVersion -ErrorAction SilentlyContinue # Deletion is not critical. Next time the build runs, it will attempt another cleanup. 
} else { 
    Write-Debug 'No file found to delete' 
} 

此外,该解决方案给服务器增加了另一种复杂性,所以我将这个问题保留几天,以查看是否有更简单的解决方案。 :)

1

而不是在构建期间启动一个进程我认为你需要安装该进程作为Windows服务并启动它。有意义的是,在构建的上下文中开始的任何进程都将在构建完成时停止。您可以使用命令行来安装/更新/启动Windows服务:

sc create [service name] [binPath= ] 

https://ozansafi.wordpress.com/2009/01/14/create-delete-start-stop-a-service-from-command-line/

+0

它是有道理的,但它也会使很多意义能够绕过它。 :) - 进程有一个通知图标,在上下文菜单中有许多调试工具,我们也需要访问该工具,因此将其作为服务运行对于此特定情况是不合适的。 :( –