実施したこと
- Gitlab(host a)へlocalからpushすると、自動で公開サーバ(host b)でgit pullを実行させる
- branchでdeploy先を切り替える
- git pullのbuild実行をSlackで通知(serviceでは飛ばなかったので、shellで実施中)
やりたい事
- herokuにpushしたときのようにGitlabCIの実行メッセージをshell表示させる方法があるか
- host aからshellでgit pullを実行させてその成否を取得できるか
http://qiita.com/toshihirock/items/461da0f60f975f6acb10
参考にさせていただき、やりたいことは大枠で達成できたのできました。
上記2点が可能か否か、またその設定方法や代替案等があるのか教えていただければと考えております。
使用環境
- host a: GitLab Community Edition 8.6.5(さくらVPS)
- GitlabrunnnerはShell typeを利用
- host b: さくらVPS
- aとbのssh疎通確認済
- branch毎のdeploy先は事前にclone済
CI設定内容
.gitlab-ci.yaml
stages: - deploy - deploy-staging deploy_job: type: deploy script: - echo $CI_BUILD_ID $CI_BUILD_REF_NAME - sudo /etc/deploy_scripts/test-gitlab-ci.sh $CI_BUILD_REF_NAME only: - master tags: - production deploy-staging_job: type: deploy-staging script: - echo $CI_BUILD_ID $CI_BUILD_REF_NAME - sudo /etc/deploy_scripts/test-gitlab-ci.sh $CI_BUILD_REF only: - staging tags: - test
1.git pushでCI実行
'$git push origin master'でGitlabのCI実行メッセージを表示ができるか否か
2.test-gitlab-ci.sh
このシェルを改善するのがよいのか、host bに別のシェルをおいて実行させるのがよいのか、別の方法がよいのか
#!/bin/bash ## 引数によるbranch判定 if [ $1 = "master" ]; then ## 公開先への接続とリモート側でのコマンド実行 ssh account@hostb "cd /var/www/production/test_gitlab-ci && git pull " ### ↑コレの成否を取得、もしくはベストプラクティスがあるのか知りたい ### 成否がとれればslackへmessage内容を変更して通知を行いたい curl -X POST --data-urlencode 'payload={"channel": "#test", "username": "webhookbot", "text": "This is posted to #test mster deployed", "icon_emoji": ":ghost:"}' fi if [ $1 = "staging" ]; then ssh account@hostb "cd /var/www/stage/test_gitlab-ci && git pull " curl -X POST --data-urlencode 'payload={"channel": "#test", "username": "webhookbot", "text": "This is posted to #test_sample and comes staging", "icon_emoji": ":ghost:"}' fi
今回CIの設定、運用をすることは初めてで理解が間違っている部分などもあるかと思いますがよろしくお願いします。
あなたの回答
tips
プレビュー