You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TFS 2017:服务器重启或Windows更新后触发构建的最优方案

Answer to Your TFS 2017 & Post-Reboot Build Trigger Question

Great question! Let's break down both parts of your scenario clearly:

Does TFS 2017 natively support triggering builds on server reboot events?

TFS 2017 doesn’t have a built-in feature that directly listens for Windows reboot events to kick off builds. But you can work around this by combining Windows native tools with TFS’s existing capabilities:

  • Leverage Windows Task Scheduler: Set up a task that triggers on specific reboot-related system events (common event IDs to watch are 6005, which logs when the OS finishes booting up, or 1074 for shutdown/restart initiations).
  • Trigger the TFS build from the task: Configure the task to run either the TFS command-line utility tf build queue or a small script that calls the TFS REST API to queue your target build definition.

Is running a PowerShell script on startup a viable alternative?

Absolutely—this is a straightforward, reliable approach, and here’s how to implement it:

  1. Write your PowerShell script: Include logic to queue your TFS build. For example, using the TFS command-line tool (make sure TFS client tools are installed on the VM):
    # Queue a build using TFS command-line
    tf build queue /collection:http://your-tfs-server:8080/tfs/YourCollectionName /definition:"Your Target Build Definition"
    
    Or if you prefer the REST API (no TFS client tools required):
    $tfsUrl = "http://your-tfs-server:8080/tfs/YourCollectionName/YourProjectName/_apis/build/builds?api-version=2.3"
    $buildDefinitionId = 123 # Replace with your build definition's ID
    $body = @{
        definition = @{ id = $buildDefinitionId }
    } | ConvertTo-Json
    
    Invoke-RestMethod -Uri $tfsUrl -Method Post -ContentType "application/json" -Credential (Get-Credential)
    
  2. Set the script to run on startup:
    • Task Scheduler (recommended): Create a new task with a trigger set to "At startup", then set the action to run powershell.exe -File "C:\Path\To\Your\Script.ps1". Configure the task to run with an account that has permissions to queue builds in TFS and access the VM’s resources.
    • Startup folder shortcut: Place a shortcut to the script in C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp (for all users) or the user-specific startup folder if you only need it to run for one account.

Key tips to keep in mind

  • Verify the account running the script/task has the "Queue builds" permission for your target TFS build definition.
  • Test the script manually first to confirm it can successfully queue the build before setting it to run automatically.
  • For reboot-triggered workflows, use event ID 6005 (OS startup complete) instead of shutdown events—it ensures the system is fully ready to run the build process.

内容的提问来源于stack exchange,提问作者Evgeny

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:03:53