【问题标题】:How to chain builds in TFS 2015?如何在 TFS 2015 中链接构建?
【发布时间】:2015-11-23 02:09:15
【问题描述】:

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

【问题讨论】:

    标签: tfs tfsbuild tfs-2015


    【解决方案1】:

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

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

    使用 tfx,您可以将任务上传到您的 TFS see details here
    简而言之,只需从 github 获取文件,通过节点安装 tfx 并运行

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

    在此之后,您可以选择 Trigger new Build Task 并对其进行配置:

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

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

    【讨论】:

    • 目前使用rest api听起来是解决这个问题的正确方向。
    【解决方案2】:

    这个问题时不时出现。官方文档literally say "not yet"(见最后一个问答条目)。还有an ancient suggestion on UserVoice,从今年3月开始就处于Planned状态。这很有希望,让我希望这将首先在 vNext 构建系统中实现。

    【讨论】:

    • TFS vNext 路线图到 2016 年第 2 季度...功能仍未出现
    【解决方案3】:

    此答案仅适用于

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

    如果是这种情况,那么你可以通过作弊来“建立链”(对我有用):

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

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

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

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

    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%
    

    【讨论】:

      猜你喜欢
      • 2010-11-13
      • 1970-01-01
      • 2017-03-16
      • 2016-03-06
      • 1970-01-01
      • 2016-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多