【问题标题】:How to compose git log for pending changes in TeamCIty如何为 TeamCIty 中的待处理更改编写 git 日志
【发布时间】:2012-06-03 09:22:18
【问题描述】:

我配置了一个 TeamCity 代理来构建我的 XCode 项目,并且我使用 github。我想在我的发行说明中自动包含 TeamCity 中所有待处理提交的描述。

如何从 github 获取它们并将它们存储在 teamcity 中?一旦我将它们放入 teamcity 变量中,我就可以轻松地将它们添加到我的构建脚本中。

【问题讨论】:

    标签: git github teamcity commit


    【解决方案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
    

    一些更详细的东西:

    1. 使用curl 从您的构建配置中获取最后一个成功的构建。您可以使用 teamcity 的替换来输入构建 ID。
    2. 请注意,curl 命令依赖于名为 rest 的 TeamCity 用户,密码为“rest”。建议修改密码。

    3. 使用 XPath/AWK 解析 XML 响应并获取最新的 git 版本

    4. 使用git log 获取上次构建的所有更改,并根据需要对其进行格式化。我只想获取提交描述并将它们写入文件。您需要通过将 git 设置为在构建之间进行清理,以确保文件在构建之间消失。注意:如果您要构建除 master 之外的任何东西,您将需要正确的分支规范。

    5. 请注意,git log 格式选项使用 %,这是团队城市替换标记,因此需要转义为 %%。

    6. 您需要配置 TeamCity 以使 .git 目录可访问。见Using git commands in a TeamCity Build Step

    7. 更改现在位于 changes.txt 文件中。在我的应用程序(编辑器改进问题)中,我使用此文件提交给 crashlytics 以获得 iOS 测试版分发。

    【讨论】:

      【解决方案2】:

      这就是我最终使用 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"
      

      一些解释:

      1. 使用curl 从您的构建配置中获取最后一次成功的构建。在我的示例中,这是 bt2,请确保将其替换为您的
      2. 使用 XPath/AWK 解析 XML 响应并获取最新的 git 版本
      3. 使用git log 获取上次构建的所有更改,并根据需要对其进行格式化。我只想获取提交描述。

      【讨论】:

      • 如何在 TeamCity 中使用 $NOTES 的值?
      • 有没有可以从团队城市获得任何关于修订的信息?
      • 感谢分享!我在设置与默认分支不同的分支时遇到了一些麻烦,但我需要添加:builds/status:SUCCESS,branch:other_branch
      【解决方案3】:

      您可以使用“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

      【讨论】:

      • 谢谢,我的所有更改都已推送到 github,因此 git log origin/master..master 将无法工作,但我仍然看到这些更改,并且 teamcity 必须以某种方式跟踪它们,只是不确定如何.
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      • 2011-12-12
      • 2014-10-08
      • 2016-12-24
      • 1970-01-01
      • 2011-03-08
      相关资源
      最近更新 更多