Created
May 19, 2014 13:51
-
-
Save memememomo/22fb42a2f7cc8b279335 to your computer and use it in GitHub Desktop.
Jenkins + plenv で、ブランチ毎のテスト実行環境を構築する ref: http://qiita.com/uchiko/items/88d6c54d5ad4ca1318a6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo yum install java-1.6.0-openjdk | |
$ sudo yum install java-1.6.0-openjdk-devel |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo /etc/init.d/jenkins start |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo chkconfig jenkins on |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo usermod -d /var/lib/jenkins -s /bin/bash jenkins |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cd /var/lib/jenkins | |
$ sudo -u jenkins ssh-keygen | |
$ sudo -u jenkins vi .ssh/config | |
$ sudo -u jenkins chmod 600 .ssh/config |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo bash - | |
# su - jenkins |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cd /var/lib/jenkins | |
$ mkdir -p .work/myapp/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cd /path/to/myapp.git/hooks | |
$ mv post-update.sample post-update | |
$ chmod 755 post-update | |
$ vi post-update |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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"}]}' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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