4

TFS 2015 中有没有办法进行两个构建,以便在第一个构建完成(成功)时触发第二个构建?旧的基于 XAML 的构建系统有解决方案,但我正在使用的新的基于脚本的系统没有解决方案。

4

3 回答 3

7

我通过创建一个自定义的 BuildTask 来实现构建的“链接”,它基本上只是对 TFS REST Api 进行适当的调用。然后它允许我定义一个我想要触发的构建定义(按名称),并在顶部添加一些条件(例如检查是否有这个定义的构建已经排队或检查某个定义的最后构建是否成功)。

如果有兴趣,我将源代码上传到github

使用 tfx 您可以将任务上传到您的 TFS在这里查看详细信息
简而言之,只需从 github 获取文件,通过节点安装 tfx 并运行

tfx build tasks upload --task-path ./triggerbuildtask

在此之后,您可以选择 Trigger new Build Task 并对其进行配置: 在此处输入图像描述

希望这可以帮助一些试图实现相同目标的人。

编辑
我将任务打包并发布在 Marketplace 上,以便在您的环境中轻松使用该任务:
Trigger Build Task

于 2017-03-12T17:06:21.320 回答
5

这个问题时不时出现。官方文档字面上说“还没有”(参见最后一个问答条目)。还有一个关于 UserVoice 的古老建议,自今年 3 月以来一直处于 Planned 状态。这很有希望,让我希望这将首先在 vNext 构建系统中实现。

于 2015-09-04T12:19:44.100 回答
1

此答案仅适用于以下情况

  • 您将 Git 与 TFS2015 一起使用
  • 您想在超级项目下链接构建子模块
  • 所有有问题的构建都是持续集成构建。

如果是这种情况,那么您可以通过作弊“链式构建”(它适用于我):

  1. 在每个子模块中添加一个带有脚本的批处理文件(提交到源代码管理),该脚本将这个子模块的分支(正在构建)上的最新提交重新添加到其超级项目。这样做的预期(副作用)效果是在超级项目的状态中引入“变化”,足以触发对该超级项目的 CI 构建。
  2. 在每个子模块的构建定义中,添加“批处理脚本”vNext 步骤。
  3. 将该步骤指向相应子模块的批处理文件。
  4. 此构建步骤需要是构建的最后一步,以确保它仅在构建成功时执行,然后执行其“mod”并触发超级项目的 CI 构建。

为了帮助您入门,请参阅下面的示例脚本。此特定脚本仅适用于文件系统中相互“嵌套”的子模块 - matreshka 样式。否则,每个子模块都需要一个自定义脚本。

请注意,它包括一些解决方法,用于解决我遇到的一些问题,使其完成我需要它做的事情(即在将更改推送到服务器之前,在我的机器上本地克隆/初始化子模块,然后进行整理文件)。

如果需要更多评论,请告诉我。

REM Name of your submodule repository...
set subRepo=%1
REM Name of your superproject (with respect to this submodule) repository...
set superRepo=%2
REM Name of the folder into which the content of submodule will be cloned ...
REM Without this alias the folder will be called the same as the repo you are cloning.
set subAlias=%3
REM Branch to link to, given by $(Build.SourceBranchName) in the parameters you pass 
REM to the "Run Batch" build step (that will be executing this batch file)...
set branch=%4

REM Repositories' URLs - ONLY SAMPLE URLS - Please use your own !!!
set superUrl="http://<YourTfsServerName>:8080/tfs/DefaultCollection/_git/%superRepo%"
set subUrl="http://<YourTfsServerName>:8080/tfs/DefaultCollection/<YourSuperProjectName>/_git/%subRepo%"

REM Get the latest commit on current branch...
git log -1 --pretty=format:"%%h" > Output.txt
for /f %%i in (Output.txt) do set commit=%%i

IF NOT EXIST %superRepo% GOTO NOWINDIR

cd %superRepo%
REM Handle the .git directory specifically...
cd .git
for /F "delims=" %%i in ('dir /b') do (rmdir "%%i" /s/q || del "%%i" /s/q)
cd ..
rmdir .git
REM Remove the rest of files and folders...
for /F "delims=" %%i in ('dir /b') do (rmdir "%%i" /s/q || del "%%i" /s/q)
cd ..
rmdir %superRepo%

:NOWINDIR
REM Clone superproject and checkout the required branch *********************************************
git clone %superUrl%
cd %superRepo%
git checkout %branch%
git pull origin %branch%
git submodule update --init --recursive -f
cd %subAlias%
git checkout %commit% 
cd ..

git add %subAlias%

git commit %subAlias% -m "Updated %subRepo% reference to %commit% as %subAlias%"
git push origin %branch%
于 2016-10-27T21:06:31.587 回答