実際の例
https://github.com/sanemat/pollyanna/pull/14
参考
Jenkins に bundle update した上で Pull Request させる
private/public repos, jenkinsでビルド, 書き込み権限のあるアカウントでpull request
Heroku で bundle update した上で Pull Request させる
private/public reps, herokuでビルド, 書き込み権限のあるアカウントでpull request
Middleman で作った web サイトを Travis + GitHub pages でお手軽に運用する
public repos, travis-ciでビルド, 書き込み権限のあるアカウントで gh-pagesにpush
(ちょっと毛色は違う)
で、このエントリは4部作目
public repos, cloudbeesでビルド, 書き込み権限のないアカウントでpull request
ちなみにたぶん、本命は herokuでbuildpackを使ってbuild, pull request だと思う。ただ、buildpackハードル高かったのでcloudbeesでやってみた。
githubアカウントの作成
cloudbeesでのビルドの設定
export POSTGRESQL_VERSION=9.2.4
export DATABASE=pollyanna_test
export USERNAME=postgres
export PASSWORD=
export NODE_VERSION=0.10.4
export EXECJS_RUNTIME=Node
export BUNDLE_DATETIME=$(TZ=JST-9 date +%Y%m%d%H%M%S)
######### POSTGRES INSTAL(first time) AND LAUNCH #########
curl -s -o use-postgresql https://repository-cloudbees.forge.cloudbees.com/distributions/ci-addons/postgresql/use-postgresql
source ./use-postgresql
######### DESTROY DATABASES AND USERS #########
psql -d postgres -c “DROP DATABASE IF EXISTS ${DATABASE};”
psql -d postgres -c “DROP USER IF EXISTS ${USERNAME};”
######### REPOPULATE SERVER WITH DATABASE AND USER FOR TEST #########
psql -d postgres -c “CREATE USER ${USERNAME} WITH CREATEDB;”
psql -d postgres -c “ALTER USER ${USERNAME} PASSWORD ‘${PASSWORD}’;”
psql -d postgres -c “CREATE DATABASE ${DATABASE} OWNER ${USERNAME};”
######### THIS CODE NOW EXITS. #########
## If you have other ‘M2 PreBuild’ steps following this
## in your configuration, they will now execute
##
## Eventually, control is given to the main build and
## the PostgreSQL server will still be running, ready
## to use!
source ./use-postgresql
source ./use-node
echo -n ${BUNDLE_DATETIME} > ./bundle_datetime.txt
gem install bundler
# unless git remote pushable exist
git remote add pushable https://${GH_TOKEN}@github.com/bot-motoko/pollyanna.git
#https://gist.github.com/kyanny/4017686
sed -i -e “s/ruby ‘2.0.0’/#ruby ‘2.0.0’/” Gemfile
bundle
git checkout -b feature/bundle-update-${BUNDLE_DATETIME}
bundle update
sed -i -e “s/#ruby ‘2.0.0’/ruby ‘2.0.0’/” Gemfile
git add Gemfile Gemfile.lock
git commit -m ‘bundle update’
git push pushable feature/bundle-update-${BUNDLE_DATETIME}
sed -i -e “s/ruby ‘2.0.0’/#ruby ‘2.0.0’/” Gemfile
cp config/database.yml.example config/database.yml
bundle exec rake db:create db:schema:load
COVERAGE=on bundle exec rake spec
exitstatus=$?
bundle exec rake db:drop
git checkout master
exit $exitstatus
build後にpull requestのtaskを起動
BUNDLE_DATETIME=$(head -n 1 ./bundle_datetime.txt)
#https://gist.github.com/kyanny/4017686
RESULT=`curl ${BUILD_URL}api/xml | perl -le ‘$_=;/(.+?)</;printf $1’`
# http://stackoverflow.com/questions/14863609/bash-a-multiword-variable-breaking-curl
curl -v \
-H “Accept: application/json” \
-H “Content-type: application/json” \
-H “Authorization: token ${GH_TOKEN}” \
-H “User-Agent: Bot-Motoko” \
-X POST \
-d@- \
“https://api.github.com/repos/sanemat/pollyanna/pulls” <<EOF
{
“title”: “Bundle $BUNDLE_DATETIME”,
“body”: “:hamster::hamster::hamster:”,
“head”: “bot-motoko:feature/bundle-update-$BUNDLE_DATETIME”,
“base”: “master”
}
EOF
cloudbees使う注意
無料枠1ヶ月300分制限
trial and errorしてる間にビルド時間は100分使ってしまった
柔軟にいろいろ入れられるが、shellで入れやすくなってるだけなので、travisみたいに全部入りな方が楽かな
特にbundleとgit pull-requestするだけの環境なので
rubyは1.9.3
他の言語と同様に選べそうに見えるけど2.0.0リリース前のしかない古い…
https://repository-cloudbees.forge.cloudbees.com/distributions/ci-addons/ruby/
なのでGemfileごにょごにょやる必要がある
Jenkinsのpluginなどなどもう覚えてない
情報の検索の仕方がよくわからない
「ruby cloudbees dev build」みたいにcloudbees dev build をつけるとドンピシャググれる
と分かった頃にはもうほぼ要らなくなってる
stackoverflowでも回答くれる
http://stackoverflow.com/questions/17136198/cloudbees-dev-cloud-postgresql-rubygems-pg-native-extension-how-to-use
shell よくわからない
jenkins guiでつらい特にpluginまわりの設定
時々反応遅かったり、dns lookupでfailになる、日本からアメリカ東海岸だからかな サポートには、俺はつながるからお前のプロバイダーの問題だろってメールもらった
hubのpull-requestコマンドって書き込み権限ないとうまく使えなくない?
coverallsが書き込み権限要求するのはやっぱり手抜きなのでは
JSTの朝方ビルドして欲しいので、時差の都合上cron設定 5 17 * * * これでJST6am過ぎに定期実行
おわり