Skip to content

Instantly share code, notes, and snippets.

@memememomo
Created May 19, 2014 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save memememomo/22fb42a2f7cc8b279335 to your computer and use it in GitHub Desktop.
Save memememomo/22fb42a2f7cc8b279335 to your computer and use it in GitHub Desktop.
Jenkins + plenv で、ブランチ毎のテスト実行環境を構築する ref: http://qiita.com/uchiko/items/88d6c54d5ad4ca1318a6
$ sudo yum install java-1.6.0-openjdk
$ sudo yum install java-1.6.0-openjdk-devel
$ sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
$ sudo rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
$ sudo yum install jenkins
$ sudo /etc/init.d/jenkins start
$ sudo chkconfig jenkins on
sudo usermod -d /var/lib/jenkins -s /bin/bash jenkins
$ cd /var/lib/jenkins
$ sudo -u jenkins ssh-keygen
$ sudo -u jenkins vi .ssh/config
$ sudo -u jenkins chmod 600 .ssh/config
$ sudo bash -
# su - jenkins
$ cd /var/lib/jenkins
$ mkdir -p .work/myapp/
$ cd /path/to/myapp.git/hooks
$ mv post-update.sample post-update
$ chmod 755 post-update
$ vi post-update
#!/bin/sh
# pushされたブランチ名を取得
BRANCH=$(git rev-parse --symbolic --abbrev-ref $1)
# jenkinsのAPIを叩く
curl http://[domain]:8080/job/myapp/build -F json='{"parameter": [{"name":"branch_name", "value":"$BRANCH"}]}'
PERL_VERSION="5.16.3"
HOME=/var/lib/jenkins
SHELL=/bin/bash
WORKDIR=/var/lib/jenkins/.work/myapp/$branch_name
BNAME=`echo $branch_name | sed -e "s/\//_/g"`
RESULT=$HOME/jobs/myapp/workspace/result-$BNAME.xml
PERL_NAME="$PERL_VERSION.$BNAME"
_BRANCH_NAME="for_test_$BNAME"
. $HOME/.bash_profile
# 作業領域存在チェック
if [ ! -d $WORKDIR ]; then
mkdir -p $WORKDIR
fi
cd $WORKDIR
# git cloneしているか
if [ ! -d .git ]; then
git clone ssh://xxx.xxx.xxx.xxx/path/to/myapp.git .
if
# ソースを取得
git fetch
git checkout master
git branch -D $_BRANCH_NAME || true
git checkout $branch_name -b $_BRANCH_NAME
# Perlの切替
plenv local system
EXISTS_PERL=''
IFS=$'\n'
for v in `plenv versions`; do
v=`echo $v | sed -e "s/[ *\n]//g"`
echo $v
if [ "$PERL_NAME" = $v ]; then
EXISTS_PERL="1"
break
fi
done
if [ "$EXISTS_PERL" = "" ]; then
plenv install 5.16.3 --as $PERL_NAME
fi
plenv local $PERL_NAME
plenv install-cpanm
# モジュールインストール
cpanm --installdeps .
cpanm TAP::Formatter::JUnit
# テスト実行
prove -lr --formatter=TAP::Formatter::JUnit t/ > $RESULT || RET=$?
# テストファイル置換(subtestに日本語が入っていると文字化けるため)
perl -i -ple 's/\[\\x([a-f0-9]{2})\]/pack("H*", $1)/egx' $RESULT
# 後処理
git checkout master
git branch -D $_BRANCH_NAME
# テスト結果を返す
exit $RET
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment