TFS:在服务器重启或 Windows 更新安装时触发构建的最佳方式 [英] TFS: Best way to trigger build on server restart, or on Windows Updates installation

查看:43
本文介绍了TFS:在服务器重启或 Windows 更新安装时触发构建的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简而言之,要求是验证我们最新发布的软件是否可以在应用最新的 Windows 更新和/或其他补丁后构建和安装.因此,构建服务器 VM 将仅为此目的而配置,构建仅需要在更新后运行.

In short, the requirement is to verify that our latest released software can be built and then installed after the latest Windows updates and/or other patches were applied. So the build server VM(s) will be configured just for this purpose and the build only needs to run after an update.

由于此类更新通常伴随着重新启动,我正在考虑触发构建和部署的服务器重新启动事件.TFS 2017 中是否存在此类选项?

Since such updates usually are followed with a restart, I am thinking of a server restart event triggering a build and deployment. Does such option exist in TFS 2017?

如果没有办法通过 TFS 做到这一点,我想,一个在启动时运行的 PowerShell 脚本应该可以工作?

If there is no way to do it through TFS then, I guess, a PowerShell script that runs on startup should work?

推荐答案

没有这样的内置函数来实现.但是,创建一个在启动时运行的 PowerShell 脚本应该可以工作.正如 Jessehouwing 所说,您可以使用 REST API 触发构建.

No such a build-in function to achieve that. However create a PowerShell script that runs on startup should work. Just as Jessehouwing said, you can create the script with the REST API to trigger builds.

  1. 创建一个脚本来触发特定的构建定义.(参考下面的示例)

  1. Create a script to trigger the specific build definition. (Reference below sample)

在启动时运行脚本:

如何安排在 Windows 中自动运行的批处理文件10/8/7

<小时>

Param(
   [string]$collectionurl = "http://server:8080/tfs/DefaultCollection",
   [string]$projectName = "ProjectName",
   [string]$keepForever = "true",
   [string]$BuildDefinitionId = "34",
   [string]$user = "username",
   [string]$token = "password"
)

# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))

function CreateJsonBody
{

    $value = @"
  {
  "definition": {
    "id": $BuildDefinitionId
  },

  "parameters": "{\"system.debug\":\"true\",\"BuildConfiguration\":\"debug\",\"BuildPlatform\":\"x64\"}"
}
"@

 return $value
}

$json = CreateJsonBody

$uri = "$($collectionurl)/$($projectName)/_apis/build/builds?api-version=2.0"
$result = Invoke-RestMethod -Uri $uri -Method Post -Body $json -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}

这篇关于TFS:在服务器重启或 Windows 更新安装时触发构建的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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