How to compose git log for pending changes in Team

2019-03-25 14:29发布

I have a TeamCity agent configured to build my XCode projects and I use github. I would like to automatically include in my release notes the descriptions from all pending commits in TeamCity.

How can I fetch them from github and store them in teamcity? Once I put them in a teamcity variable I can easily add them to my build script.

3条回答
对你真心纯属浪费
2楼-- · 2019-03-25 14:38

THis is how I ended up doing this using a bash script:

#!/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"

Some explanations:

  1. Use curl to fetch the last successful build from your build configuration. In my sample this is bt2, make sure to replace it with yours
  2. Use XPath/AWK to parse the XML response and get the last git version
  3. Use git log to get all changes form last build and format them anyway you want. I wanted to just get the commit descriptions.
查看更多
萌系小妹纸
3楼-- · 2019-03-25 14:42

I found a couple of issues when I implemented the above answer, which are updated here:

#!/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

Some more detailed things:

  1. Use curl to fetch the last successful build from your build configuration. You can use teamcity's substitution to put in the build id.
  2. Note that the curl command relies on having a TeamCity user called rest, with a password "rest". Suggest changing the password.

  3. Use XPath/AWK to parse the XML response and get the last git version

  4. Use git log to get all changes form last build and format them anyway you want. I wanted to just get the commit descriptions and write them to a file. You'll need to make sure the file goes away between builds by setting up git to clean in-between. NB: If you're building off of anything other than master, you'll need the right branch spec here.

  5. Note that the git log format option uses %, which is the teamcity substitution marker, and thus needs to be escaped as %%.

  6. You need to do configure TeamCity to make the .git directory accessible. See Using git commands in a TeamCity Build Step

  7. The changes are now in the changes.txt file. In my application (editor improving question) I used this file to submit to crashlytics for an iOS beta distribution.

查看更多
等我变得足够好
4楼-- · 2019-03-25 15:00

You could use the "Adding or Changing a Build Parameter from a Build Step" feature in order to update some build parameters right from a build step.

You would need a step which would call git log origin/master..master (see "git: list commits not pushed to the origin yet"), after fetching from GitHub.
(See "Using Team City With Git " for the TeamCity configuration with GitHub, and make sure your TeamCity is runnig with the right account)

查看更多
登录 后发表回答