Travis CIはリポジトリのすべてのコミットに対してビルドを実行し、そのコミットのビルドの成否をGitHubに返してくれるようになっています。 pull requestを送った時などに見られるチェックマークがそれです。

プライベートリポジトリではJenkinsを使っているので、Jenkinsでも同様の仕組みを実現してみました。 仕組みは簡単で、すべてのコミットのビルドの前後にGitHubのCommit Status APIを叩くだけです。 自分はiOSアプリのビルドタスクをRakefileにまとめているので、スクリプトを以下のように設定しました。

curl -X POST -H "Authorization: token ACCESS_TOKEN" https://api.github.com/repos/:owner/:repo/statuses/$(git rev-parse HEAD) -d "{ \
  \"state\": \"pending\", \
  \"target_url\": \"${BUILD_URL}\", \
  \"description\": \"The build is pending.\" \
}"

rake clean
rake cocoapods

if rake test
then
curl -X POST -H "Authorization: token ACCESS_TOKEN" https://api.github.com/repos/:owner/:repo/statuses/$(git rev-parse HEAD) -d "{ \
  \"state\": \"success\", \
  \"target_url\": \"${BUILD_URL}\", \
  \"description\": \"The build has succeeded.\" \
}"
else
curl -X POST -H "Authorization: token ACCESS_TOKEN" https://api.github.com/repos/:owner/:repo/statuses/$(git rev-parse HEAD) -d "{ \
  \"state\": \"failure\", \
  \"target_url\": \"${BUILD_URL}\", \
  \"description\": \"The build has failed.\" \
}"
fi

ACCESS_TOKENはGitHubのAccount settings -> Applications -> Personal access tokensから作成できます。 URLをhttps://yourcompany.com/api/v3/...に変更することでGitHub Enterpriseにも対応できます。

この設定は同じリポジトリ内のコミットのみに対応しており、フォークされたリポジトリのコミットにも対応するには Refspecに+refs/pull/*/head:refs/remotes/origin/pr/*に追加したり、 Commit Status APIの/:owner/:repoの箇所を適切に変更するといった追加の手順が必要になりそうです(未検証)。 あるいは、GitHub pull request builder pluginを使うという方法もあるようです。

参考