git - TeamCity 将参数从服务器传递到构建代理

标签 git continuous-integration teamcity

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

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

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

有没有办法将 version 从 checkout 服务器传递给构建代理? (不更改 VCS checkout mode 以构建代理)?

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

最佳答案

Is there a way to pass version from checkout server to build agent? (without changing VCS checkout mode to build agent)?

简短的回答是你做不到

您可以尝试做的是:

- 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

Gist 是,既然做不到,就需要有点创意


示例钩子(Hook)可以是:

预接收 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;

关于git - TeamCity 将参数从服务器传递到构建代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36279960/

相关文章:

git - 添加许多提交后如何取消提交?

git - 无法从 mac 终端 pull/推到 github 上的远程仓库

continuous-integration - GPU 包的持续集成服务?

amazon-web-services - 如何在 AWS 代码管道中创建管道作为代码

export - 如何将 TestExecute/TestComplete 结果导出到 teamcity?

git - 为什么 git 在 "resolving deltas"时需要网络连接?

xcode - 如果我在构建之前不清理,我会遇到问题吗?

Visual Studio Team Services 中的 Git,Visual Studio 2012 项目 - 无法从构建部署

.net - MSBuild 使用错误版本的 sgen.exe 生成 XmlSerializer dll?

msbuild - 如何使用 MSBuild 构建 Xamarin iOS 应用程序?