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

如何在TFS 18构建任务中按预定义变量选择并检出Git自定义分支

回答:TFS 2018构建任务中自定义分支检出与动态分支选择

Hey there! I’ve worked with TFS 2018 quite a bit, so let’s walk through your two questions clearly—both are straightforward once you know where to look. Here’s how to tackle each one:


1. 在TFS 2018构建任务中检出自定义源代码分支

This is the basic setup for targeting a specific branch, and it’s done right in the core "Get Sources" step:

  • Step 1: Open your existing build definition, or create a new one. Navigate to the Get Sources tab (this is the first tab by default, where TFS configures how it pulls code).
  • Step 2: Under the Repository section, confirm your Git repo is selected. Look for the Branch dropdown—by default, it might be set to main or master. Click the dropdown and either:
    • Select your custom branch directly from the list (if it shows up), or
    • Manually type the full branch name (e.g., feature/user-authentication) if it’s not listed.
  • Step 3: Save your build definition. Next time you run it, TFS will pull code from your chosen custom branch.

对应截图说明

![TFS 2018 Get Sources 自定义分支配置](截图展示:Get Sources选项卡中,Branch字段选择/输入了自定义分支feature/user-authentication,仓库信息已正确关联)


2. 依据CI流水线启动前的变量值动态选择Git分支

To make the branch selection dynamic based on a variable you set right before starting the pipeline, follow these steps:

Step 1: Create a custom pipeline variable

  • Go to the Variables tab in your build definition.
  • Click the Add button to create a new variable. Name it something clear like TargetBranch, set a default value (e.g., main for fallback), and check the box that says "Allow users to override this value when running a pipeline" (this lets you change the branch every time you start the build).
  • Save the variable.
  • Go back to the Get Sources tab.
  • Replace the static branch name in the Branch field with the variable reference: $(TargetBranch). TFS will automatically resolve this variable to its value when the pipeline runs.

Step 3: Run the pipeline with a custom branch value

  • When you click Queue build to start the pipeline, you’ll see a parameters page. Look for your TargetBranch variable, type in the branch name you want to use (e.g., bugfix/login-issue), and click Queue.
  • The pipeline will now pull code from the branch you specified in the variable.

对应截图说明

  1. TFS 2018 添加可覆盖的自定义变量
  2. ![Get Sources 引用变量作为分支](截图展示:Get Sources选项卡的Branch字段填写了$(TargetBranch))
  3. ![启动流水线时修改变量值](截图展示:Queue build页面中,TargetBranch字段已被修改为bugfix/login-issue,准备启动构建)

小提示

  • Make sure the branch name you enter matches exactly what’s in your Git repo—typos will cause the build to fail at the Get Sources step.
  • Ensure the TFS build service account has read access to the branch you’re targeting.
  • If you’re using branch naming conventions (e.g., feature/*), you can even use wildcards in the variable, but keep it simple unless you need that flexibility.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.22 07:52:43