【问题标题】:TeamCity pass parameter from server to build agentTeamCity 将参数从服务器传递到构建代理
【发布时间】:2016-04-07 15:36:23
【问题描述】:

我想获得构建代理的提交计数以进行手动版本控制,

version = git rev-list --count "branchname"

git 在构建代理上不可用,因为我已签出“自动在服务器上”。

有没有办法将version 从结帐服务器传递给构建代理? (无需更改VCS checkout mode 来构建代理)?

我正在运行最新的 9.1.6 版本 TC。

【问题讨论】:

    标签: git continuous-integration teamcity


    【解决方案1】:

    有没有办法将版本从结帐服务器传递给构建代理? (不改变 VCS 结帐模式来构建代理)?

    简短的回答是你做不到

    您可以尝试这样做:

    - Add a version file to your repository,   
    - **before** commiting use a git hook to update this file with the desired number
    - Read the content of the file on your build server and you have it.
    
    - Use a git hook to call a job on your build server which gets the 
      branch name and the number of commits and store it for later use somewhere
    

    重点是,既然你做不到,你就需要一点点创意


    示例钩子可以是:

    pre-receive hook

    #!/bin/sh
    
    branchName=$1
    
    # Get the number of commits you need to store:
    version = git rev-list --count $branchName
    
    #############
    # Now write the desired number to the desired file and let
    # the build read it
    #############
    
    # Output colors
    red='\033[0;31m';
    green='\033[0;32m';
    yellow='\033[0;33m';
    default='\033[0;m';
    
    # personal touch :-)
    echo "${red}"
    echo "                                         "
    echo "                   |ZZzzz                "
    echo "                   |                     "
    echo "                   |                     "
    echo "      |ZZzzz      /^\            |ZZzzz  "
    echo "      |          |~~~|           |       "
    echo "      |        |-     -|        / \      "
    echo "     /^\       |[]+    |       |^^^|     "
    echo "  |^^^^^^^|    |    +[]|       |   |     "
    echo "  |    +[]|/\/\/\/\^/\/\/\/\/|^^^^^^^|   "
    echo "  |+[]+   |~~~~~~~~~~~~~~~~~~|    +[]|   "
    echo "  |       |  []   /^\   []   |+[]+   |   "
    echo "  |   +[]+|  []  || ||  []   |   +[]+|   "
    echo "  |[]+    |      || ||       |[]+    |   "
    echo "  |_______|------------------|_______|   "
    echo "                                         "
    echo "${default}"
    
    # set the exit code to 0 so the push will occur
    exit 0;
    

    【讨论】:

      【解决方案2】:

      基本上,不,你不能以你想要的方式做你想做的事,你不能在获取更改时只在服务器上执行一些命令行命令。

      为什么不正确配置内部版本号格式和构建计数器并使用它们呢?也可以在构建期间动态设置构建号。

      【讨论】:

      • 我想使用提交计数作为版本号的一部分,如果我使用内置版本控制将不可用。
      • 好吧,你可以添加一个包含提交计数的文件,它是由 pre-commit hook 编写的。
      【解决方案3】:

      我在构建过程中做了非常相似的事情来获取当前分支名称和 git hash。遗憾的是,不,您无法在结帐模式设置为服务器的构建期间执行这些 git 命令。您需要更改签出模式以构建代理以确保 .git 文件夹存在于工作目录中。从好的方面来说,我认为这没有什么坏处。它不会复制远程,因此构建代理很难将更改推送到主存储库。

      就@hexct 而言,变基或合并或任何数量的事情都可能使这个计数不可靠。最好将自己与 git hash 联系起来,而不是 # of commits。

      【讨论】:

        【解决方案4】:

        为什么你需要 git counter?

        最简单的方法是遵循 TeamCity 的原则。使用 TeamCity 计数器而不是 git 计数器。每次提交后设置构建触发器。并将标签设置回 git 以查看 git 历史中的构建版本。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2011-03-29
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-11-10
          相关资源
          最近更新 更多