我有一个TeamCity代理配置为构建我的XCode项目,我使用github。我想在我的发行说明中自动包含TeamCity中所有待处理提交的描述。
如何从github获取它们并将它们存储在teamcity中?一旦我将它们放入teamcity变量中,我就可以轻松地将它们添加到我的构建脚本中。
答案 0 :(得分:21)
这就是我最后使用bash脚本执行此操作的方法:
#!/bin/bash
curl -o lastBuild.tmp "http://localhost:8111/app/rest/buildTypes/id:bt2/builds/status:SUCCESS" --user rest:rest
last_commit=`xpath lastBuild.tmp '/build/revisions/revision/@version'| awk -F"\"" '{print $2}'`
echo "##Last commit = $last_commit"
# prepare build notes
NOTES=`git log --pretty=format:"- %s" $last_commit..origin/master`
echo "this is it:$NOTES"
一些解释:
curl
从构建配置中获取上次成功的构建。在我的示例中,这是bt2,请务必将其替换为您的git log
从上次构建中获取所有更改,并根据需要对其进行格式化。我想获得提交说明。答案 1 :(得分:2)
您可以使用“Adding or Changing a Build Parameter from a Build Step”功能直接从构建步骤更新某些构建参数。
从GitHub获取后,您需要一个可以调用git log origin/master..master
(参见“git: list commits not pushed to the origin yet”)的步骤。
(有关使用GitHub的TeamCity配置,请参阅“Using Team City With Git ”,并确保您的TeamCity is runnig with the right account)
答案 2 :(得分:1)
当我实现上述答案时,我发现了一些问题,这些问题在此更新:
#!/bin/bash
curl -o lastBuild.tmp "http://localhost:8111/app/rest/buildTypes/id:%system.teamcity.buildType.id%/builds/status:SUCCESS" --user rest:rest
last_commit=`xpath lastBuild.tmp '/build/revisions/revision/@version'| awk -F"\"" '{print $2}'`
git log --pretty=format:"- %%s" $last_commit..origin/master > changes.txt
一些更详细的事情:
curl
从构建配置中获取上次成功的构建。您可以使用teamcity的替换来输入构建ID。请注意,curl命令依赖于让TeamCity用户名为rest,并使用密码" rest"。建议更改密码。
使用XPath / AWK解析XML响应并获取最后一个git版本
使用git log
从上次构建中获取所有更改,并根据需要对其进行格式化。我想获取提交描述并将它们写入文件。您需要确保文件在构建之间消失,方法是设置git来清理它们。注意:如果您正在建立除主人以外的任何东西,那么您需要在此处使用正确的分支规范。
请注意,git log
格式选项使用%,即teamcity替换标记,因此需要作为%%进行转义。
您需要配置TeamCity以使.git目录可访问。请参阅Using git commands in a TeamCity Build Step
更改现在位于changes.txt文件中。在我的应用程序(编辑器改进问题)中,我使用此文件向iOS beta版发行版的crashlytics提交。